- I conform to a protocol, so I honour this interface - Apply a common set of behaviours in a single inheritance system. UITableViewDataSource UIApplicationDelegate NSFetchedResultsSectionInfo
struct Homer { ... var krusty: KrustyDelegate } Whenever we want to do something Krusty like - we bounce out to the delegate But what about the other Franchisees?
We could declare an array of Franchisees let franchisees: Array = [“Homer”, “Ned”, “Smithers”] But then we have to declare a delegate object for each. of them, or use some kind of factory method.
FizzBuzz — If the number is a multiple of 3, print “Fizz” — If the number is a multiple of 5, print “Buzz” — If the number is a multiple of 3 and 5, print “FizzBuzz” — Otherwise, just print the number
And you can fizz buzz that as well [Shape(sides: 1), Shape(sides: 3), Shape(sides: 15)].fizzBuzz([(3, “Fizz”), (5, “Buzz”)]) // [“1”, “Fizz”, “FizzBuzz”] The mechanics of doing the actual FizzBuzz has been removed from the configuration of the FizzBuzz.