Get Flexible

Episode Summary

This week we talk about defining interfaces, constructing an intention, and using messages to discover objects.

Episode Notes

Chapter 4: Creating Flexible Interfaces

At an object-oriented level, applications are made up of classes but defined by messages

Defining Interfaces

Imagine a restaurant kitchen. Customers order food off a menu. The menu is a kind of public interface. Within the kitchen, messages get passed and the way a meal is prepared (implementation details) are private to the customer.

Public Interfaces

Private Interfaces

The public interface is a contract that articulates the responsibilities of your class

Example App: Bicycle Touring Company

Use case

Constructing an Intention

Asking for "What" Instead of Telling "How"

The distinction between a message that asks for what a sender wants and a message that tells the receiver how to behave may seem subtle but the consequences are significant

Seeking Context Independence

The best possible situation is for an object to be completely independent of its context. An object that could collaborate with others without knowing who they are or what they do could be reused in unanticipated and novel ways

Using Messages to Discover Objects

Recall the use case: A customer, in order to choose a trip, would like to see a list of available trips of appropriate difficulty, on a specific date, where rental bicycles are available

Writing Code That Puts Its Best (Inter)Face Forward

Methods in the public interface should:

JP’s: HackingWithSwift

John’s Pick: -