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 operation can called after it, , on.
    • so reserveticketoperation has public buyticketoperation execute();
    • then buyticketoperation has public renderticketoperation execute();
  • b)

    • use kind of context state machine records position of execution using enums , has factory obtaining next operation.

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

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -