<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>True too, but I think there is some overreaction too especially with the heavy push from FP programmers. Truth is that composition, inheritance, and functional programming are all tools and not religions. We can learn from each how to code better in general and mix and match.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">Although this talk predates Swift's default methods/mixins, and so it stops earlier than you might like, it makes a lot of valid points:</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature"><span style="background-color: rgba(255, 255, 255, 0);">Watch “Somewhere Between Tomorrowland and Frontierland - Daniel Steinberg” on Vimeo: <a href="https://vimeo.com/124349158">https://vimeo.com/124349158</a></span><br><br>Sent from my iPhone</div><div><br>On 7 Jan 2016, at 19:41, Charles Constant &lt;<a href="mailto:charles@charlesism.com">charles@charlesism.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">&gt;&nbsp;<span style="font-size:13px">I am not sure that the language should discourage a feature it supports and impose friction on it because it could be abused.</span><div><span style="font-size:13px"><br></span></div><div>Especially since the OOP philosophy is falling out of fashion anyway. Thousands of CompSci profs, and programming blogs, all saying "we've come to our senses, OOP is confusing". Adding Abstract classes to Swift isn't going to turn that ship around.<br></div><div><span style="font-size:13px"><br></span></div><div>&nbsp;</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 7, 2016 at 11:27 AM, Goffredo Marocchi <span dir="ltr">&lt;<a href="mailto:panajev@gmail.com" target="_blank">panajev@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Hello David,</div><div><br></div><div>I am not sure that the language should discourage a feature it supports and impose friction on it because it could be abused. Composition does not mean you should never subclass and Swift should not make it trickier to implement inheritance although I could agree it should not bend over backwards for it either.</div><div>I think this proposal goes along this direction.</div><div><br></div><div>With that said, this is where protocols and protocol extensions with default methods come in, but there we have the static dispatching of the methods declare in the protocol extension with the default implementation unless they were also created in the original protocol in which case the default implementation is only used if the type implementing the protocol does not override it... That area needs some revisiting too perhaps.<br><br>Sent from my iPhone</div><div><div class="h5"><div><br>On 7 Jan 2016, at 18:42, David James via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br></div></div></div><blockquote type="cite"><div><div><div class="h5">Not sure the language direction should <i>encourage</i> inheritance based structures, which abstract classes and methods do. That’s not to say that inheritance is dead, but that a modern language should encourage and support compositional patterns rather than inheritance based patterns.&nbsp;<div><br><div><blockquote type="cite"><div>On Jan 7, 2016, at 7:19 PM, charles--- via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div>+1<br><br>I have loads of "pretend abstract" classes littered with stuff like this:<br><br> &nbsp;&nbsp;&nbsp;var boo:Bool! { return nil /*DUMMY*/ }<br><br>It takes a significant amount of energy atm to plan a Swift project because there are quirky differences between: protocol / subclass / class extension. It's not so straightforward to pick the most appropriate one.<br><br><br><br>Sent from my iPhone<br><br><blockquote type="cite">On Jan 7, 2016, at 9:55 AM, David Scrève via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br># Abstract classes and methods<br><br>* Author(s): David Scrève<br><br>## Introduction<br><br>When developing framework and reusable, we need to develop classes that are partially <br>abstract with partial implementation. Protocol and protocol extensions provide this, but <br>they cannot have attributes as classes have.<br>A partial class combines the behavior of a class with the requirement of implementing methods<br>in inherited class like protocols.<br><br>Swift-evolution thread: [link to the discussion thread for that proposal](<a href="https://lists.swift.org/pipermail/swift-evolution" target="_blank">https://lists.swift.org/pipermail/swift-evolution</a>)<br><br>## Motivation<br>Like pure virtual methods in C++ and abtract classes in Java and C#, frameworks development <br>sometimes required abstract classes facility.<br>An abstract class is like a regular class, but some methods/properties are not implemented <br>and must be implemented in one of inherited classes.<br>An abstract class can inherit from other class, implements protocols and has members <br>attributes as opposite from protocols.<br>Only some methods and properties might be abstract.<br>The goal of abstract classes is to encapsulate a generic behavior that may need some <br>specific implementation methods which are not known in abstract class. This behavior <br>requires attributes that are used by internal abstract class method.<br><br>Example : <br>Considere a generic RESTClient that is included in a framework : <br><br>```swift<br>class RESTClient {<br><br> &nbsp;&nbsp;var timeout = 3000<br><br> &nbsp;&nbsp;var url : String {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert(false,"Must be overriden")<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ""<br> &nbsp;&nbsp;}<br><br> &nbsp;&nbsp;func performNetworkCall() {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let restURL = self.url<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("Performing URL call to \(restURL) with timeout \(self.timeout)")<br> &nbsp;&nbsp;}<br>}<br><br>```<br><br>And an implementation : <br>```swift<br>class MyRestServiceClient : RESTClient {<br> &nbsp;&nbsp;override var url : String {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return "<a href="http://www.foo.com/client" target="_blank">http://www.foo.com/client</a>"<br> &nbsp;&nbsp;}<br><br>}<br>```<br><br>As you can see, url properties must be implemented by inherited class and should not be <br>implemented by ancestor.<br>As workaround, we have added assertion, but this error is only detected at runtime and not <br>at compile time and might create crash for end-user.<br><br>## Proposed solution<br>We propose to add a new keyword to indicate that a method or a property is abstract and <br>not implemented in current class.<br>This indicates that method or properties must be implemented in inherited class that can <br>be implemented.<br>We propose the keyword abstract that must be added to class and property/method : <br><br>```swift<br>abstract class RESTClient { &nbsp;&nbsp;&nbsp;<br> &nbsp;&nbsp;&nbsp;var timeout = 3000<br><br> &nbsp;&nbsp;abstract var url : String { get }<br><br> &nbsp;&nbsp;func performNetworkCall() {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let restURL = self.url<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("Performing URL call to \(restURL) with timeout \(self.timeout)")<br> &nbsp;&nbsp;}<br>}<br>```<br><br>And an implementation : <br>```swift<br>class MyRestServiceClient : RESTClient {<br> &nbsp;&nbsp;override var url : String {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return "<a href="http://www.foo.com/client" target="_blank">http://www.foo.com/client</a>"<br> &nbsp;&nbsp;}<br><br>}<br>```<br><br>## Detailed design<br>An abstract class cannot be instanciated. <br><br>If a class contains one or more abstract methods/properties, it must be declared abstract.<br><br>A class that inherits from abstract must be declared abstract if it does not implements <br>all inherited methods/properties.<br><br>If you try to implement an abstract class or a inherited class that implements partially <br>abstract methods/properties, you will get a compiler error.<br><br>As for override keyword, abstract properties apply on setter, getter and observers. <br><br>When declaring an abstract property, you must specify which methods must be implemented : <br>get, set, didSet, willSet. <br><br>If you do not specify anything, only setter and getter are made <br>abstracts as below : <br><br>```swift<br> &nbsp;&nbsp;abstract var url : String<br>```<br><br>Observers provides default empty implementation.<br><br>Type is mandatory for abstract properties since it cannot be inferred.<br><br>## Impact on existing code<br>This change has no impact on existing code, but might change the ABI that is being <br>stabilizing in Swift 3.0.<br><br>## Alternatives considered<br>As first reading, it seems that protocols and protocol extensions might fit the need. It <br>actually does not because abstract classes can have attributs and properties that <br>protocols does not support.<br><br>An alternative solution would be to add attributes to protocols and protocol extensions, <br>but this might break compatibility with Objective-C runtime.<br><br><br><br>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></blockquote>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></div></blockquote></div><br><div>
<div style="color:rgb(0,0,0);font-family:Verdana;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Verdana;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><span style="border-collapse:separate;color:rgb(0,0,0);font-family:Verdana;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px"><div style="word-wrap:break-word"><span style="border-collapse:separate;color:rgb(0,0,0);font-family:Verdana;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px"><div style="word-wrap:break-word"><span style="border-collapse:separate;color:rgb(0,0,0);font-family:Verdana;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px"><div style="word-wrap:break-word"><div>David James</div></div></span></div></span></div></span></div></div>
</div>
<br></div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=dXNHRXbGTqqssqDI7Hn7KyogJzdRthQdFNkQ7LxhQVNry9sph5hESoA6TNdjnNVPcVMxSN8lqQqyXEPIv6En8ujd7gUhO12BUdALqV-2BbTy78TzpqgVzWURgX2iGhI2obHobRt26LZKkYHDQthO-2BqRpmksbIR7LPqURkiCqOeWF-2B2OPmjLeIvVBS5p7czXbrwHf6B-2FI73ciBJWyUb6NZ8x4A8GwYhoXUj9makalz3vro-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">

</div></blockquote><span class=""><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></span></div></blockquote></div><br></div>
</div></blockquote></body></html>