Public isn’t that open anymore?!
I’m very excited about Swift 3 and all the changes that are coming. One of the changes i found out about when attending this CocoaHeads meetup is that there’s a new access control type: open.
Basically declaring a class as ‘open’ means that the class can be subclassed outside the module. So this access control type is one step further than the public control type.
It even goes further: if you don’t declare a method as open then a subclass outside the module won’t be able to override this method.
Be aware of this major change when you are creating or maintaining modules (or frameworks, if you prefer calling it the old way).
So i wonder why Apple made this change. One of the biggest reasons i can come up with is: Apple doesn’t like subclassing anymore, or at least not without giving it a good thought. Slowly yet steady they are trying to push us to the idea of ‘Favor composition over inheritance’. Watch Apple’s (in my opinion very nice) presentation Protocol and Value Oriented Programming in UIKit from WWDC 2016.
Is this a good thing? Well, ending up with a module (/framework) that feels like Lego blocks is something very nice. Instead of a module telling you what and how to implement your app. Is this a huge change? Yes it certainly is. It’s something to get used to, but hey that’s developer’s life :-) For now i would say: if you start a new module then try it out and think of composition.