File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes best design pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "best design pattern " Watch "best design pattern " New topic
Author

best design pattern

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
Which technique or design pattern best suited for the below scenario

Generally if a method(A) in an object calls a method(B) in other object., once the method B finish its task then it should go back to method A and proceed .

But my requirement is, once Method B finished it task then It never go back to Method A but go the next state based on some logic.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
That doesn't sound like a normal object-oriented scenario.

Foo calls Bar, which passes control back to Foo. That's it. If Bar wants to pass control elsewhere it can call Rab, but control will pass back. A method can't decide which method calls it, and a called method can't decide what its calling method does afterwards.

You can try things like throwing Exceptions, but that is a very poor bit of design.
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
That doesn't sound like a normal object-oriented scenario

in Model-view-controller.First request goes to Controller then controller only invoke respective business classes ,control come back to controller then it invoke the view to display the result.so the controller play a core role in this .all load exist in controller .

I think that it is violation clear separation.service layer's(model) flow is controlled by controller.

instead of control hold flow control for through out the process,it just pass the control to its next entity for further processing.model only decide when to go back to controller.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

I didn't quite understand your second post, jacob, but based on just your first post, I'd suggest you look at the Command pattern. In the command pattern, objects are used to represent work to do. Your code can request work by creating a Command and putting it into a queue of Commands to be executed. After your code registers a command, it can return, or do other work; the command will eventually be executed by the command queue.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: best design pattern