Local reasoning means that when you look at the code, right in front of you, you don’t have to think about how the rest of your code interacts with that one function.
Initial cell layout was a
But this information for the 2 subviews does not need to be held inside a
UITableViewCell sublcass, so let’s make it a struct:
So instead of subclassing DecoratingLayoutCell, we use composition:
By doing that, we can use exactly the same code in any
UIView sublass since the layout logic is decoupled from cells.
But if we want to support different types of content (e.g. SpriteKit nodes instead of views), how can we abstract this further?
layout function only sets the
frame property of
layout, we can represent that with a protocol:
and then set the type of
description to that protocol using retroactive modelling:
NOTE: At this point, the layout logic is not using UIKit, which means it can be applied to AppKit as well.
Now, we want
decoration to be of the same type, so that we can add their children as subviews or subnodes accordingly. In order to accomplish that, we can use generics:
WWDC 2016, session 419: Protocol and Value Oriented Programming in UIKit Apps