File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

best design pattern

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 580
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

Joined: Oct 13, 2005
Posts: 46320
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: 580
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 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

Joined: Jul 08, 2003
Posts: 24199

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:
subject: best design pattern
It's not a secret anymore!