its one of a Creational Patterns which consist of:
- Factory: which creates objects.
- Protocol: which defines the methods that the products should implement.
- Products: the objects that are created
its one of the Creational Patterns which consist of:
- Product: which is a complex object to be created.
- Builder: accepts step by step inputs and handle the creation of product.
- Director: accepts inputs and coordinates with the builder.
its one of a Behavioral Patterns because it's all about objects communication[one-to-one] which consist of three parts:
- Delegating object: Itβs the object that has a delegate. The delegate is usually held as a weak property to avoid a retain cycle.
- Delegate protocol: which defines the methods that the delegate should implement.
- Delegate: This is the helper object that implements the delegate protocol.
its one of a Behavioral Patterns which consist of four parts:
- Client: Object using an adapter and depends on the protocol
- protocol: which defines the methods we need
- Adaptee/legacy object: cannot be modified directly so we need add extension or create new adapter
- adapter: which helps us to make the incompatible objects deal with each other
protocol Target {
func request()
}
class Adaptee {
func specificRequest() {
print("Specific request")
}
}
class Adapter: Target {
private let adaptee: Adaptee
init(adaptee: Adaptee) {
self.adaptee = adaptee
}
func request() {
adaptee.specificRequest()
}
}
let adaptee = Adaptee()
let adapter = Adapter(adaptee: adaptee)
adapter.request() // Prints "Specific request"