lundi 23 février 2015

Adding new commands with Command Design Pattern

I'm having a dilemma regarding Command Design Pattern. Receiver is the interface for a class that knows how to perform operations.


In the example case given in the link, receiver class Stock Trade knows how to perform 2 operations, StockTrade#buy and StockTrade#sell. Those operations correspond to 2 existing commands, BuyStockOrder and SellStockOrder.


However, what if additional commands would need to be added, for example FooStockOrder and BarStockOrder? Then, the Receiver interface would have to be changed (and all existing implementations), therefore violating the Open-Closed principle.


How to tackle that problem in a way that Receiver is (almost) never changed?


Aucun commentaire:

Enregistrer un commentaire