Tutorial by Examples

Singletons are a frequently used design pattern which consists of a single instance of a class that is shared throughout a program. In the following example, we create a static property that holds an instance of the Foo class. Remember that a static property is shared between all objects of a class...
In class-based programming, the factory method pattern is a creational pattern that uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created. Wikipedia reference protocol SenderProtocol { func send(packa...
The observer pattern is where an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. It is mainly used to implement distributed event handling systems. The Observer pattern ...
In object-oriented design, the chain-of-responsibility pattern is a design pattern consisting of a source of command objects and a series of processing objects. Each processing object contains logic that defines the types of command objects that it can handle; the rest are passed to the next proce...
In computer programming an iterator is an object that enables a programmer to traverse a container, particularly lists. Wikipedia struct Turtle { let name: String } struct Turtles { let turtles: [Turtle] } struct TurtlesIterator: IteratorProtocol { private var current = 0 p...
The builder pattern is an object creation software design pattern. Unlike the abstract factory pattern and the factory method pattern whose intention is to enable polymorphism, the intention of the builder pattern is to find a solution to the telescoping constructor anti-pattern. The telescopi...

Page 1 of 1