I want to create a Java interface with a number methods. But I want the user of the interface to only be able to invoke methods in the sequence or order that I define. For instance buyTicket()
should not be called before reserveTicket()
. Q: Is there a design pattern or any tips on how to go about this?
I considered:
A)
- Interface is wrapped, only showing the next possible method. Each invocation of a method returns a new
operation
that can be called after it, and so on. - So
ReserveTicketOperation
haspublic BuyTicketOperation execute();
- Then
BuyTicketOperation
haspublic RenderTicketOperation execute();
- Interface is wrapped, only showing the next possible method. Each invocation of a method returns a new
B)
- Use come kind of
context
state machine that records the position of execution using enums and has a factory for obtaining the next operation.
- Use come kind of
Any thoughts or suggestions are greatly appreciated. Thanks
Aucun commentaire:
Enregistrer un commentaire