Kalaimaan

Doing simple things to make great life

Patterns in JAVA (Design Patterns)

Posted by kalaimaan on February 11, 2009

Creational Patterns

Type of Patterns

1. Creational Patterns

  • The Factory Pattern

  • The Abstract Factory Pattern

  • The Singleton Pattern

  • The Builder Pattern

  • The Prototype Pattern

2. Structural Patterns

  • The Adapter Pattern

  • The Bridge Pattern

  • The Composite Pattern

  • The Decorator Pattern

  • The Façade Pattern

  • The Flyweight Pattern

  • The Proxy Pattern

3. Behavioral Patterns

  • The Command Pattern

  • The Interpreter Pattern

  • The Iterator Pattern

  • The Mediator Pattern

  • The Memento Pattern

  • The Observer Pattern

  • The State Pattern

  • The Strategy Pattern

  • The Template Pattern

  • The Visitor Pattern

Creational Patterns
All of the creational patterns deal with the best way to create instances of objects. This is important because your program should not depend on how objects are created and arranged. In Java, of course, the simplest way to create an instance of an object is by using the new operator.

Fred = new Fred(); //instance of Fred class

However, this really amounts to hard coding, depending on how you create the object within your program. In many cases, the exact nature of the object that is created could vary with the needs of the program and abstracting the creation process into a special “creator” class can make your program more flexible and general.

The Factory Method provides a simple decision making class that returns one of several possible subclasses of an abstract base class depending on the data that are provided.

The Abstract Factory Method provides an interface to create and return one of several families of related objects.

The Builder Pattern separates the construction of a complex object from its representation, so that several different representations can be created depending on the needs of the program.

The Prototype Pattern starts with an initialized and instantiated
class and copies or clones it to make new instances rather than creating new
instances.

The Singleton Pattern is a class of which there can be no more than
one instance. It provides a single global point of access to that instance.

Structural Patterns
Structural patterns describe how classes and objects can be combined to form larger structures. The difference between class patterns and object patterns is that class patterns describe how inheritance can be used to provide more useful program interfaces. Object patterns, on the other hand, describe how objects can be composed into larger structures using object composition, or the inclusion of objects within other objects.

The Adapter pattern, used to change the interface of one class to that of another one.

The Bridge pattern, intended to keep the interface to your client program constant while allowing you to change the actual kind of class you display or use. You can then change the interface and the underlying class separately.

The Composite pattern, a collection of objects, any one of which may be either itself a Composite, or just a primitive object.

The Decorator pattern, a class that surrounds a given class, adds new capabilities to it, and passes all the unchanged methods to the underlying class.

The Façade pattern, which groups a complex object hierarchy and provides a new, simpler interface to access those data.

The Flyweight pattern, which provides a way to limit the proliferation of small, similar class instances by moving some of the class data outside the class and passing it in during various execution methods.

The Proxy pattern, which provides a simple place-holder class for a more complex class which is expensive to instantiate.

Behavioral Patterns
Behavioral patterns are those patterns that are most specifically concerned with communication between objects.

The Observer pattern defines the way a number of classes can be notified of a change,

The Mediator defines how communication between classes can be simplified by using another class to keep all classes from having to know about each other. The Chain of Responsibility allows an even further decoupling between classes, by passing a request between classes until it is recognized.

The Template pattern provides an abstract definition of an algorithm.

The Interpreter provides a definition of how to include language elements in a program.

The Strategy pattern encapsulates an algorithm inside a class

The Visitor pattern adds function to a class

The State pattern provides a memory for a class’s instance variables.

The Command pattern provides a simple way to separate execution of a command from the interface environment that produced it.

The Iterator pattern formalizes the way we move through a list of data within a class.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: