Shared base classes
It’s very common to have a shared base class that is subclassed many times by classes that have mutually exclusive behavior:
// A button that can be pressed. class Button {
func press() {}
}
// A button that is composed entirely of an image. class ImageButton: Button {
var image: Image
}
// A button that renders as text. class TextButton: Button {
var text: String
}
In this example, you can imagine numerous Button subclasses that share only the
fact that they can be pressed. The ImageButton and TextButton classes likely have entirely different mechanisms to render the appearance of a button, so they might have to implement their own behavior when the button is pressed.
You can see here how storing image and text — not to mention any other kind of button there might be — in the Button class would quickly become impractical. It makes sense for Button to be concerned with the press behavior, and the subclasses to handle the actual look and feel of the button.