Tutorial by Examples

A very common guideline in object oriented design is "as little as possible but as much as necessary". This also applies to the strategy pattern: It is usually advisable to hide implementation details, for example which classes actually implement strategies. For simple strategies which do...
Strategy: Strategy is a behavioural pattern, which allows to change the algorithm dynamically from a family of related algorithms. UML of Strategy pattern from Wikipedia : import java.util.*; /* Interface for Strategy */ interface OfferStrategy { public String getName(); public dou...
The following is a simple example of using the strategy pattern without a context class. There are two implementation strategies which implement the interface and solve the same problem in different ways. Users of the EnglishTranslation class can call the translate method and choose which strategy t...
The purpose of this example is to show how we can realize the Strategy pattern using Java 8 functional interfaces. We will start with a simple use case codes in classic Java, and then recode it in the Java 8 way. The example problem we using is a family of algorithms (strategies) that describe dif...
Example from www.phptherightway.com <?php interface OutputInterface { public function load(); } class SerializedArrayOutput implements OutputInterface { public function load() { return serialize($arrayOfData); } } class JsonStringOutput implements Output...

Page 1 of 1