[swift-evolution] Add code to super methods.
dabrahams at apple.com
Tue Nov 29 09:05:35 CST 2016
> On Nov 29, 2016, at 1:48 AM, Tino Heth <2th at gmx.de> wrote:
>> Methods that need to be called when they are overridden are
>> almost always a result of poor design.
> Without an explanation or data to back this statement, it's hard to argue about it, and I won't make random shots.
> But as a matter of fact, we have to deal with methods which require the behaviour in question now, and I have no idea when Cocoa will be replaced with something better.
That's a great point. I just don't want to punish those who create methods with default implementations that are designed to be completely replaced in subclasses. I suppose that *could* encourage more use of protocols, but that seems like a very unfriendly way to reach a protocol-oriented utopia ;-)
> Just out of sheer curiosity:
> What would be a better design for a method like viewWillAppear? The obvious alternative that is possible with current Swift and template methods looks really ugly to me:
> Not only would you have to add two empty methods to each subclass of UIViewController,
Why two, and why empty? UIViewController would supply its own empty default implementation.
> but also rely on that those methods are only overridden once in the hierarchy of inheritance.
There's no law saying you *can't* call super if you absolutely must build a two-level hierarchy below UIViewController (though there are ways around that—the main one being to avoid inheritance hierarchies). I just don't want to create a world where you're always expected to call super everywhere, which is what would happen if we always warn when you don't call super.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution