My study notes for the various objected oriented refactoring techniques and design patterns. Includes code samples as well as written text explanations.

Note: Refactoring Guru is likely a much better resource than these notes.


Design Principles

Design Patterns

Structural Patterns

Structural patterns explain how to assemble objects and classes into larger structures, while keeping the structures flexible and efficient.

Pattern Description
Composite Pattern Compose objects into tree structures and then work with these structures as if they were individual objects.
Adapter Pattern Allows objects with incompatible interfaces to collaborate.
Decorator Pattern Dynamically attach new behaviours to objects by placing these objects inside special wrapper objects that contain the behaviours.

Behavioural Patterns

Behavioral patterns take care of effective communication and the assignment of responsibilities between objects.

Pattern Description
Strategy Pattern Extract varying behaviours into separate classes and allow these to be changed in a context object dynamically.
State Pattern Allows objects to alter its behaviour when its internal state changes.
Observer Pattern Define a subscription mechanism to notify multiple objects about any events that happen to an observed object.
Template Method Pattern Define the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure.
Visitor Pattern Separate algorithms from the objects on which they operate. Allow new behaviours to be added to existing classes without modifying them (mostly).

Creational Patterns

Creation patterns provide various object creation mechanisms that increase flexibility and code reuse.

Pattern Description
Factory Method Provide an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.
Abstract Factory Pattern Produce familes of related objects without specifying their concrete classes.
Builder Pattern Construct complex objects step by step.
Singleton Pattern Ensure that a class has only one instance, while providing a global access point to this instance.