Design patterns - Object Orientated Programming
Design patterns are solutions to problems that occur often in software design.
Object orientated programming is a programming paradigm that uses objects and classes to design software applications based on a business domain.
These objects and classes describe and build out functionality and features of real world concepts, ideas or actions. You in a sense recreating the real world in code.
Design patterns and OOP go hand in hand, as designs patterns give us a way to solve common problems in our code.
Design patterns are solutions to problems that occur often in software design.
They can be use to solve common problems in your code. They can also be customised to fit your specific needs.
Design patterns give us a shared vocabulary to talk about solutions we can apply to problems in our code.
Design principles
Good object orientated design is built on a few key principles:
- Identify the aspects of your application that may vary, then separate them from what does not.
- Pogramme to an interface and not to an implementation
- Favour composition over inheritance
- Classes should be open for extension but closed for modification
Pattern types
Design patterns can be categorised into three main types:
- Creational patterns
- Structural patterns
- Behavioural patterns
Creational patterns
Creational patterns are concerned with the creation of objects. They are used to create objects in a system in a manner suitable to the situation.
- Singleton
- Factory
- Abstract Factory
- Builder
Structural patterns
Structural patterns are concerned with how objects are composed. They help ensure that if one part of a system changes, the entire system does not need to do the same.
- Adapter
- Bridge
- Composite
- Decorator
- Facade
- Flyweight
- Proxy
Behavioural patterns
Behavioural patterns are concerned with the interaction between objects. They help ensure that objects can communicate with each other in a predictable manner.
- Chain of Responsibility
- Command
- Interpreter
- Iterator
- Mediator
- Memento
- Observer
- State
- Strategy
- Template Method
- Visitor
UML modelling
UML (Unified Modelling Language) is a standardised way to model software systems. It is a visual language that helps you communicate your design ideas.
Type | Description |
---|---|
<-- | Inheritance |
*-- | Composition |
o-- | Aggregation |
--> | Association |
-- | Link (Solid) |
..> | Dependency |
..> | Realization |
.. | Link (Dashed) |
<.. | Generalization |
source: Mermaid