to change the behavior of a given object in runtime, based on its current state. • Adding a new state is very easy. Cons: • Many classes which are not part of the system design are added.
one and make then interchangeable. • Lets the algorithm vary independently from the client that use it. • Choose the preferred algorithm to solving the problem, according to the current situation.
to change the behavior of a given object in runtime, based on the current situation. • Adding a new algorithm is very easy. Cons: • Client must be aware of a different strategies. • Creates many classes which are not part of the system design directly.
of an aggregate object sequentially without exposing its underlying implementation. • Provides a uniform interface for traversing different kinds of collections.
arr.iterator(); Integer i = it.next(); // for loop using iterator for (Iterator it = arr.iterator(); it.hasNext(); it.next()) { ... } // Syntactic suger (foreach loop) for (Integer i : arr) { ... }