Question d’entretien chez Amazon

How would you take a convoluted inheritance tree and use composition instead?

Réponse à la question d'entretien

Utilisateur anonyme

29 mars 2018

Using Swift, you can create protocols for desired functional groups. Then, you can create protocol extensions that have concrete methods. Finally, make your concrete objects conform to said protocols via extensions. This is similar to what other languages call “mixing.” You can also use property and initializer injection to accept supporting objects. For example, use the Strategy Design Pattern.

1