Design Patterns

Creational:

AbstractFactory: creational methods returning the Factory itself which can be used to create another abstract/interface type.
ex: ServiceFactory#newInstance()

Builder: creational methods returning the instance itself.
ex: StringBuilder.append(); java.lang.Appendable#append()

Factory Method: creational methods returning a implementation of abstract/interface type. ex: Calendar#getInstance()

Prototype: creational method returning a different instance of itself with the same properties ex: Object#clone()

Singelton: recognized by the creational method returning the same instance (usually itself) everytime. ex: Runtime#getRuntime()

Structural:

Adapter: creational methods taking an instance of different abstract/interface type and returning an implementation of own/another abstract/interface which decorate/overrides the given instance. ex: Arrays.asList(), XmlAdapter.marshal() and XmlAdapter.unMarshal()

Bridge: decouple an abstraction from implementation. creational methods taking an instance of different abstract/interface type and returning an implementation of own/another abstract/interface which delegates/uses the given instance.

ex: persistenceImpl API where persistence can be changed at runtime to a fileSystem or Database implementation http://thecafetechno.com/tutorials/design-patterns/bridge-pattern-in-java-with-sample-code-to-download/. Another  example is Collections.newSetFromMap() or Collections.singeltonList(),  Collections.singeltonSet(),  Collections.singeltonMap().

Composite: part-whole object hierarchies that let’s client treat individual objects and group of objects similarly.

Decorator: creational method taking an instance of same abstract/interface type which adds additional behavior. ex: Collections.checkedXXX(), Collections.unModifiableXXX(), Collections.synhronizedXXX(), javax.servlet.http.HttpServletRequestWrapper/HttpServletResposeWrapper()

Facade: Provides a single interface, to interact with a set of interfaces

Flyweight: creational methods returning  a cached instance (multiton idea). ex: Integer.valueOf(int x)

Proxy: creational methods which return an implementation of given abstract/interface type which in turn delegates/uses a different implementation of the given type. ex: java.lang.reflect.Proxy

Useful Links:

http://www.vincehuston.org/dp/

http://bookshelf.theopensourcelibrary.org/Elemental%20Design%20Patterns.pdf

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