From the course: Practical Design Patterns in Swift
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Sharing of common data - Swift Tutorial
From the course: Practical Design Patterns in Swift
Sharing of common data
- [Instructor] The flyweight design pattern saves memory and reduces the creation costs for similar objects. We can apply it if we have numerous objects that rely on the same immutable data. The flyweight pattern minimizes memory usage by sharing the common data among multiple objects. To make it work we need to separate the parts that can change from the immutable set of properties. The unchanging parts get stored in the flyweight and are protected from changes. We need to extract the properties that might change. The clients can manage these mutable properties and pass them through the flyweight object when necessary. The shared immutable part is called Intrinsic state and the properties that can change represent the Extrinsic state of the object. Here is an example to illustrate the process of identifying the extrinsic and intrinsic state. In computer games we often see objects that look similar. Plants, rocks, buildings, vehicles and so on. Let's take a concrete case. A Spaceship.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.