Never Subclass Components Edit on GitHub
CKCompositeComponent. (If you need to perform advanced layout by overriding
computeLayoutThatFits: you may subclass
CKComponent directly, but this should be rare.)
- Subclassing is difficult to reason about. There is no
finalkeyword in Objective-C, so any method can be overridden in a subclass. It’s impossible to read a superclass and know what is and isn’t overridden somewhere.
- Subclassing makes refactoring the superclass difficult. If the superclass is refactored to rename or remove a method, every subclass must be inspected to see if they were overriding the method. This is often skipped or forgotten, leading to silent bugs.
For example, imagine that we’re adding a new “highlighted” card component. It should look just like a regular card component, but have a yellow background color. Don’t do this:
CardComponent take the color as a parameter and then subclass
CKCompositeComponent to create your highlighted component: