Examples of GoF Design Patterns in core Java. Feel free to suggest new examples or mail corrections!
I’ve been working with Java for more than a decade. This page is extracted from my stackoverflow.com answer.
In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation.
Recognizeable by creational methods returning the factory itself which in turn can be used to create another abstract/interface type.
Recognizeable by creational methods returning the instance itself.
Recognizeable by creational methods returning an implementation of an abstract/interface type.
Recognizeable by creational methods returning a different instance of itself with the same properties.
Recognizeable by creational methods returning the same instance (usually of itself) everytime.
In software engineering, structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities.
Recognizeable by creational methods taking an instance of different abstract/interface type and returning an implementation of own/another abstract/interface type which decorates/overrides the given instance.
Recognizeable by creational methods taking an instance of different abstract/interface type and returning an implementation of own abstract/interface type which delegates/uses the given instance.
Recognizeable by behavioral methods taking an instance of same abstract/interface type into a tree structure.
Recognizeable by creational methods taking an instance of same abstract/interface type which adds additional behaviour.
Recognizeable by behavioral methods which internally uses instances of different independent abstract/interface types.
Recognizeable by creational methods returning a cached instance, a bit the “multiton” idea.
Recognizeable by creational methods which returns an implementation of given abstract/interface type which in turn delegates/uses a different implementation of given abstract/interface type.
In software engineering, behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication.
Recognizeable by behavioral methods which (indirectly) invokes the same method in another implementation of same abstract/interface type in a queue.
Recognizeable by behavioral methods in an abstract/interface type which invokes a method in an implementation of a different abstract/interface type which has been encapsulated by the command implementation during its creation.
Recognizeable by behavioral methods returning a structurally different instance/type of the given instance/type; note that parsing/formatting is not part of the Interpreter pattern, determining the given pattern and how to apply it is.
Recognizeable by behavioral methods sequentially returning instances of a different type from a queue.
Recognizeable by behavioral methods taking an instance of different abstract/interface type (usually using the command pattern) which delegates/uses the given instance.
Recognizeable by behavioral methods which internally changes the state of the whole instance.
Recognizeable by behavioral methods which invokes a method on an instance of another abstract/interface type, depending on own state.
Recognizeable by behavioral methods which changes its behaviour depending on the instance’s state which can be controlled externally.
Recognizeable by behavioral methods in an abstract/interface type which invokes a method in an implementation of a different abstract/interface type which has been passed-in as method argument into the strategy implementation.
Recognizeable by behavioral methods which already have a “default” behaviour definied by an abstract type.
Recognizeable by two different abstract/interface types which has methods definied which takes each the other abstract/interface type; the one actually calls the method of the other and the other executes the desired strategy on it.
ZEEF on social media