java - Design pattern for interface that determines order of method invocation -
i want create java interface number methods. want user of interface able invoke methods in sequence or order define. instance buyticket() should not called before reserveticket(). q: there design pattern or tips on how go this?  
i considered:
a)
- interface wrapped, showing next possible method. each invocation of method returns new 
operationcan called after it, , on. - so 
reserveticketoperationhaspublic buyticketoperation execute(); - then 
buyticketoperationhaspublic renderticketoperation execute(); 
- interface wrapped, showing next possible method. each invocation of method returns new 
 b)
- use kind of 
contextstate machine records position of execution using enums , has factory obtaining next operation. 
- use kind of 
 
any thoughts or suggestions appreciated. thanks
my immediate feeling: don't @ all pattern.
if inner logic of methods requires them always call them in order; exposing implementation detail make easy use interface wrong.
meaning: instead of trying somehow force "client code" adhere specific order should design interfaces in way client code doesn't need care "order".
in particular example problem seems ticket object can "reserved" or "bought"; , of course, "bought" tickets can turned back, refunded, ...
in case, "solution" have different classes "reserved" tickets , "bought" tickets. don't need worry tries refund ticket "reserved".
Comments
Post a Comment