P
pcrepieux
Hi,
I recently meet a problem while "playing" with the state pattern. I was
wondering if each of the member function dedicated to handle events open(),
close(), ack() could be change to something like process(openEv& ev),
process(closeEv& ev), ... no problem with this point. Going further in this
way, i thought that the process member function would be a great candidate
for a template. Hum ... it is not. The process function have to be virtual
in the base state class. Trying to approach something similar, here is what
i did :
I used a variant type (boost::variant) that holds any of my event: typedef
boost::variant<pdu1,pdu2,pdu3> pdu;
In the base state class I defined a virtual process(pdu p) and then a
process(pdu p) in each concrete state class that uses a visitor (inherited
from boost::static_visitor) to call the process(xxxEv).
I'd like to know if this is a pertinent solution or if this simply highlight
that if i need to do something like that, something is wrong in the design.
Pierre
I recently meet a problem while "playing" with the state pattern. I was
wondering if each of the member function dedicated to handle events open(),
close(), ack() could be change to something like process(openEv& ev),
process(closeEv& ev), ... no problem with this point. Going further in this
way, i thought that the process member function would be a great candidate
for a template. Hum ... it is not. The process function have to be virtual
in the base state class. Trying to approach something similar, here is what
i did :
I used a variant type (boost::variant) that holds any of my event: typedef
boost::variant<pdu1,pdu2,pdu3> pdu;
In the base state class I defined a virtual process(pdu p) and then a
process(pdu p) in each concrete state class that uses a visitor (inherited
from boost::static_visitor) to call the process(xxxEv).
I'd like to know if this is a pertinent solution or if this simply highlight
that if i need to do something like that, something is wrong in the design.
Pierre