The abstract base class is very similar to the AnyAnimal public wrapper due to the following:
- It conforms to our base protocol.
- It's an abstract class so provides a top implementation for the private box.
- It defines a generic parameter, T or F, bound to the associated type.
The convention begs to call this class _Any#MY_PROTOCOL#Base<>. As the design pattern requires the implementation of this class as an abstract class, we implement it with fatalError():
private class _AnyAnimalBase<F>: Animal where F: Food {
var preferredFood: F? {
get { fatalError() }
set { fatalError() }
}
var name: String { fatalError() }
func eat(food: F) { fatalError() }
}