Design Patterns
General Responsibility Assignment Software Patterns
- Controller
- Creator
- High Cohesion
- Low Coupling
- Indirection
- Information Expert
- Polymorphism
- Protected Variations
- Pure Fabrications
SOLID Principles
- Single Responsibility Principle
- Open ( for extension ) / Closed ( for modification )
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
GoF
- Composition vs Aggregation
- Aggregation does not imply Ownership
- University is composed of Departments ( Same Lifecycle)
- Departments is aggregation of Professors ( Different Lifecycle )
Structural
- Adapter / Wrapper
- Bridge - Decouple Abstraction from Implementation allowing two to evolve independently.
- abstract Shape > CircleShape extends Shape (abstraction)
- interface DrawingApi - FirstDrawingApi implements DrawingApi (implementation)
- Shape encapsulates DrawingApi
- Composite - The composite pattern describes that a group of objects is to be treated in the same way as a single instance of an object. The intent of a composite is to "compose" objects into tree structures to represent part-whole hierarchies. Implementing the composite pattern lets clients treat individual objects and compositions uniformly
- Decorator - Add additional responsibilities keeping same interface.
- Facade - Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
- Flyweight - A flyweight is an object that minimizes memory use by sharing as much data as possible with other similar objects - String Pool in Java.
- Front Controller - The pattern relates to the design of web applications. It "provides a centralized entry point for handling requests
- Module - Group several related elements, such as classes, singletons, methods, globally used, into a single conceptual entity
- Proxy - Provide a surrogate or placeholder for another object to control access to it.
Behavioural
- Command - an object is used to represent and encapsulate all the information needed to call a method at a later time. This information includes the method name, the object that owns the method and values for the method parameters
- Interpreter - specifies how to evaluate sentences in a language. The basic idea is to have a class for each symbol (terminal or nonterminal) in a specialized computer language. Expression.execute(). Plus, Minus, Mulltiply, Divide all have own implementation of execute().
- Iterator -
- Mediator - Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
- Momento - that provides the ability to restore an object to its previous state (undo via rollback).
- Null Object - Avoid null references by providing a default object.
- Observer OR Publish/Subscribe - Define a one-to-many dependency between objects where a state change in one object results in all its dependents being notified and updated automatically
- State
- Strategy - enables an algorithm's behavior to be selected at runtime. The strategy pattern
- defines a family of algorithms,
- encapsulates each algorithm, and
- makes the algorithms interchangeable within that family.
- Template Method
- Visitor - a way of separating an algorithm from an object structure on which it operates. A practical result of this separation is the ability to add new operations to existing object structures without modifying those structures. It is one way to follow the open/closed principle.
- Chain of responsibility - Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it
- Dispose Pattern - the dispose pattern is a design pattern which is used to handle resource cleanup and prevent resource leaks in runtime environments that use automatic garbage collection. The fundamental problem that the dispose pattern aims to solve is that, because objects in a garbage-collected environment have finalizers rather than destructors, there is no guarantee that an object will be destroyed at any deterministic point in time. The dispose pattern works around this by giving an object a method (usually called
Dispose
or similar) which frees any resources the object is holding onto.
Creational
- Builder
- Builder class is public static nested class.
- The Parent class constructor is private
- build() / instance() in builder calls new Parent(builder) while passing the builder instance to Parents constructor.
- Factory
- Abstract Factory
- Prototype
- Singleton
- Lazy Initialization
- Object Pool
Concurrency
- Active Object
- Balking
- Double Checked Locking
- Join
- Lock
- Monitor
- Reactor
- Read-Write Lock
- Reactor
- Scheduler
- Thread Pool
No comments:
Post a Comment