December 2018
Intermediate to advanced
414 pages
10h 19m
English
The private box will be a type that implements the abstract base class. The goal of the private box is to provide a wrapper around the concrete object implementing the PAT and forward all of the calls to the boxed object.
Following the conventions also suggests that you should use _Any#MY_PROTOCOL#Box as a class name for this component:
private final class _AnyAnimalBox<A: Animal>: _AnyAnimalBase<A.FoodType> { // The target object, that is an Animal var target: A init(_ target: A) { self.target = target } // Overrides of the abstract classes's implementation // Forward all invocations to the concrete target override var name: String { return target.name } override var preferredFood: A.FoodType? { get { return target.preferredFood ...
Read now
Unlock full access