All these events were classes, which had methods for bzness logic.
And we had our factory class – OrderEvent as –
Class OrderEvent {
Virtual EnterOrder * createEnterOrder() = 0;
Virtual ExecOrder * createEnterOrder()= 0;
Virtual SendOrder * createEnterOrder()= 0;
…
};
Depending upon US or UK, we had following various derived classes –
UKEnterOrder/USEnterOrder
UKExecOrder/USExecOrder etc
And UKOrderEvent/USOrderEvent
Class UKOrderEvent {
EnterOrder * createEnterOrder() {
return new UKEnterOrder();
}
ExecOrder * createExecOrder() {
return new UKExecOrder();
}
};
Class USOrderEvent {
EnterOrder * createEnterOrder() {
return new USEnterOrder();
}
ExecOrder * createExecOrder() {
return new USExecOrder();
}
};
In the main(), it was used like this –
OrderEvent *ptr = NULL;
If(country = UK)
ptr = new UKOrderEvent;
Else if (country = US)
ptr = new USOrderEvent;
ptr->createEnterOrder();
The beauty here is that - the OrderEvent classes can be made Singleton, and this is a good example of Singleton classes, in addition to normal banking login, logger, COW type of singleton examples.
No comments:
Post a Comment