Please enable JavaScript.
Coggle requires JavaScript to display documents.
Deep-Dive: Design Patterns (Classification (Concurrency patterns (MDP…
Deep-Dive: Design Patterns
Classification
Creational Patterns
Singleton
Sources
Singleton Design Pattern in C#
on Csharp Star
Wikipedia
Creational Design Patterns
on Csharp Star
Ensure a class has only one instance.
Provide a global point of access to it.
Mentioned by GoF and CleanCode
Addressing issues
How can the sole instance of a class be accessed easily?
How can a class control its instantiation?
How can be ensured that a class has only one instance?
How can the number of instances of a class be restricted?
Solution
Hide the constructor of the class.
Define a public static operation (getInstance()) that returns the sole instance of the class.
Implementation - double check when locking to prevent race conditions in parallel access from multiple threads.
A singleton implementation may use lazy initialization, where the instance is created when the static method is first invoked.
Common uses
Facade objects are often singletons because only one Facade object is required.
State objects are often singletons.
The abstract factory, builder, and prototype patterns can use Singletons in their implementation.
Singletons are often preferred to global variables
Logger, cache, etc.
Differences with static class
In c# a static class cannot implement an interface. When a single instance class needs to implement an interface for some business reason or IoC purposes, you can use the Singleton pattern without a static class.
You can clone the object of Singleton but, you can not clone the static class object
Singleton object stores in Heap but, static object stores in stack
A singleton can be initialized lazily or asynchronously while a static class is generally initialized when it is first loaded
Multiton
???
Lazy initialization
???
Factory method
???
Examples in .NET:
Convert class
Parse()/TryParse() methods
Dependency Injection
???
Builder
???
Examples in .NET:
StringBuilder class
Abstract factory
Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
Articles
Wikipedia
Creational Design Patterns
on Csharp Star
Fabryka abstrakcyjna(abstract factory) i jej rodzaje by DevMan Blog
Mentioned by GoF and CleanCode
Addressing issues
How can a class be independent of how the objects it requires are created?
How can families of related or dependent objects be created?
How can an application be independent of how its objects are created?
Pros
The intent in employing the pattern is to insulate the creation of objects from their usage and to create families of related objects without having to depend on their concrete classes.
This allows for new derived types to be introduced with no change to the code that uses the base class.
Use of this pattern makes it possible to interchange concrete implementations without changing the code that uses them.
Solution
Encapsulate object creation in a separate (factory) object.
That is, define an interface (AbstractFactory) for creating objects, and implement the interface.
A class delegates object creation to a factory object instead of creating objects directly.
RAII
Resource acquisition is initialization
???
Prototype
???
Object pool
???
Behavioral patterns
Command
Chain of responsibility
Blackboard
Interpreter
Iterator
???
Examples in .NET:
IEnumerable interface, foreach, yield
Mediator
Memento
Null object
Observer or Publish/subscribe
???
Examples in .NET:
events / delegates
IObservable<out T>, IObserver<in T> interfaces
Articles
Obserwator by DevOnBoard Blog
Servant
Specification
State
Strategy
Template method
Visitor
Structural patterns
Bridge
Composite
Adapter / Wrapper / Translator
Examples in .NET:
Runtime Callable Wrappers - RCW
(adapters that let .NET managed code easily
call into legacy COM code via a .NET API)
???
Decorator
???
Examples in .NET:
Stream class and its derivatives
(all streams in .NET provide the same basic functionality, however each stream functions differently)
Articles
Decorator by DevOnBoard Blog
Extension object
Facade
Flyweight
Front controller
Marker
Module
Proxy
Twin
Concurrency patterns
Balking
Active Object
Binding properties
Blockchain
Double-checked locking
Event-based asynchronous
Guarded suspension
Join
Lock
MDP
Messaging design pattern
Monitor object
Reactor
Read-write lock
Scheduler
Thread pool
Thread-specific storage
Other
Page object
[TODO] Architectural patterns
Sources
Articles
Software design pattern
on Wikipedia
Architectural pattern
on Wikipedia
Creational Design Patterns
on Csharp Star
What design patterns are used throughout the .NET Framework?
Books
Design Patterns
by Gang of Four
Code Complete
by Steve McConnell