GOF talks about frameworks for "Factory method" pattern. Frameworks need objects but implementation of objects depends upon application hence an abstract method to create the object is created. Also as return type is needed so interface for the object needed is defined. Actual objects are created by subclasses (concrete Application) . This is a creational pattern.
For strategy pattern the only change is that the encapsulating class does not know the implementation of certain behavior hence it abstracts it in a method , uses it but leaves the implementation to the subclasses. This is behavioral pattern.
Is the only differences between the two are
1. Factory method is creational and Strategy is behavioural.
2. Factory method abstracts a method to create an object where as Strategy pattern abstracts a method for some policy or algorithm.
Aucun commentaire:
Enregistrer un commentaire