Singleton is very popular in Cocoa. We can find different use cases. The following are two examples.
let default = NotificationCenter.default
let standard = UserDefaults.standard
Do you remember our system structure for car? We have a protocol and different implements like the code below.
protocol Car { func drive()}
class Sedan: Car { func drive() { print("drive a…
class Sedan: Car { func drive() { print("drive a
Decorator is a structural pattern to add new functions to class or instance at runtime. Compared to inheritance, it has more advantages in flexibility and scalability. We will still use our car model in this article.
I found many people accessed my articles on design patterns in Swift through search…