Implementations of various design patterns in Swift.
Key takeaways:
- Always begin designing a system with it's
behavior
rather than beginning withdata
. This approach adds clarity to identify components in thesystem
. This is said otherwise in the famous sayingProgram to an interface not an implementation!
Swift specific inputs:
- Prefer defualt implementations in protocol over inheritence.
- Init could go on protocol. This'd enforce
required
initialization. - Avoid concrete classes as much as your design allows. Leverage protocol extensions over concrete classes.
References:
- https://sourcemaking.com/design_patterns
- https://swiftcraft.io/decorator-pattern-swift/
- http://www.oopwithswiftasapro.com/2017/08/11/decorator-pattern/
- https://learning.oreilly.com/library/view/design-patterns-elements/0201633612/
- https://stablekernel.com/swift-design-patterns-in-practice-the-decorator-pattern/
- https://benoitpasquier.com/observer-design-pattern-swift/