• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

best design pattern

 
jacob deiter
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47310
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic