Please enable JavaScript.
Coggle requires JavaScript to display documents.
Design patterns (Strategy (Encaplulates a family of related algorithms…
Design patterns
Strategy
-
-
-
Example - Order Delivery Type - Create interface for each delivery type and inject them into price calculation method
Template method
Implementation (Inheritance) - Child classes override only methods they need from base class and method call order is implemented in base class
-
Result - Different implementation of same algorithm or workflow, variation of details of each algorithm step
Related patterns
-
Factory Method - define a common interface for creating new instances of types with many implementations
-
Unit of Work
Intent
-
Enables to change the state of multiple objects and save their state in one logical transaction, e.g. unitOfWork.Commit() method
Implementation (EF) - Create UnitOfWork class that has all related object and a Commit/DoWork() method that saves all changes
-
-
Repository
-
Result
-
Calling code knows only about the interface methods - it doesnt know which data access implementation is used
-
Increased level of abstractin - less duplicated code, code is more maintainailble, flexible and testable
Implementation - interface with methods(Add, Remove, Find...) for each data entity and Concrete classes implement the data access logic (SQL DB, Web Service, File System)
Related patterns - Unit of Work, Specification, Identity Map, Decorator
Facade
Intent and Result - Provides a simple, purpose-built interface to a larger, more complex body of code or interfaces
Implementation - Wrapper class for complex or bad APIs - data access, third party libraries, services, legacy code, etc
Related patterns - Adapter, Flyweight, Mediator
Factory
-
-
Implementation - Create a factory class that has a CreateInstance method that returns a Concrete class based on a Create Instance parameter or configuration(appConfig, from database...)
NullObject
Intent
-
-
Allow methods to be called on Null objects, unlike a null reference
-
-
Implementation - Create a null object that derives from abstract base class (singleton object) or implemets interface