dimanche 20 mai 2018

Strategy Pattern Java

I have a question regarding strategy pattern in java. In the first diagram we can see definition of the Strategy pattern. Context is composed of a Strategy interface, The context could be anything that would require changing behaviors - a class that provides sorting functionality perhaps.

The Strategy is simply implemented as an interface, so that we can swap ConcreteStrategys in and out without effecting our Context.

Normal strategy pattern Strategy pattern

Now lets look at the second diagram, . Suppose we use Strategy pattern. Classes ConcreteStrategyA and ConcreteStrategyB need to call the client to perform the algorithm they implement.

Any reason why you would need the interface Client Interface?

Aucun commentaire:

Enregistrer un commentaire