Please enable JavaScript.
Coggle requires JavaScript to display documents.
Subject - Coggle Diagram
Subject
Design Pattern
OO Principles
-
-
Program to interfaces, not implementations
-
-
-
-
-
Patterns
Strategy
The Trategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
Observer
Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically
Decorator
Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality
Bullet points
Inherirance is one form of extension, but not necessarily the best way to achieve flexibility in out designs
-
-
-
-
-
Decorators change the behavior of their components by adding new functionality before and/or after method calls to the component
-
Decorators are typically transparent to the client of the component; that is, unless the client is relying on the component's concrete type
Decorators can result in many small objects in our design, and overuse can be complex
Factory
Abstract Factory
Provide an interface for creating families of related or depedent objects without specifying their concrete classes
Factory method
Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to the subclasses
Bullet points
-
Simple Factory, while not a bone fide design pattern, is a simple way to decouple your clients from concrete classes
Factory Method relies on inheritance: object creation is delegated to subclasses which implement the factory method to create objects
Abstract Factory relies on object composition: object creation is implemented in methods exposed in the factory interface
All factory patterns promote loose coupling by reducing the dependency of your application on concrete classes
-
The intent of Abstract Factory is to create families of related objects withou having to depend on their concrete classes
The Dependency Inversion Principle guides us to avoid dependencies on concrete types and strive for abstractions
Factories are a powerful technique for coding to abstractions, not concrete classes
Singleton
-
bullet points
-
-
Java's implementation of the Singleton Pattern makes use of a private constructor, a static method combined with a static variable
Examine your performance and resource constraints and carefully choose an appropriate Singleton implementation for multithreaded applications
Beware of the double-checked locking implementation; it is not thread-safe in versions before Java 2, version 5
Be careful if you are using multiple class loaders; this could defeat the Singleton implementation and result in multiple instances
If you are using a JVM earlier than 1.2, you'll need to create a registry of Singletons to defeat the garbage collector
-