Behavioral Patterns

A behavioral class pattern uses inheritance for distribution of behavior. The interactions between the objects should be such that they are talking to each other and still are loosely coupled. The loose coupling is important part of n-tier architectures. Client should be loosely coupled in order to avoid dependencies.

There are 6 type of Behavioral Patterns

  • Command Pattern
  • Observer pattern
  • Iterator pattern
  • Strategy pattern
  • Template pattern
  • Visitor pattern

Command Pattern

In this pattern client request passes as a command and based on this command request maps to particular modules as result request module invokes. However command pattern invokes particular object based on command.

Observer Pattern

This pattern defines one to many dependency between objects so that if one object changes state, all its dependent objects are inform and change automatically. Observer pattern is used when a change to one object requires changing others, and youdon't know how many objects need to be changed.

Iterator Pattern

Iterator pattern allow use to iterate through a collection of data using a common interface without knowing internal structure such as list give you a way to access its elements without exposing internal implementation. Iterator pattern support multiple traversals of collection objects.

Strategy Pattern

Define a family of algorithms, encapsulate each one, and make them interchangeable.Strategy lets the algorithm vary independently from clients that use it. In this different algorithms are represented as Concrete Strategy classes, and they share a common Strategy interface.

Template Pattern

This pattern implement the invariant parts of an algorithm once and leave it upto subclasses to implement the behavior that can vary. Separate that code which change frequently and encapsulate that code from other code.

Visitor Pattern

By this way, execution algorithm of element can varies as visitor varies. We use this pattern when an object structure contains many classes of objects with differing interfaces, and you want to perform operations on these objects that depend on their concrete classes.