<div dir="ltr"><div>Hello,</div><div><br></div>This is an interesting example. I can't refute it without questioning decisions/intent rather than code so I'll just say that the `abstract` quality you're after still seems like it should be fit into the protocol family of features.<br><div><br></div><div>TJ</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 4, 2015 at 3:56 AM, David Scrève <span dir="ltr"><<a href="mailto:david.screve@dlta-studio.com" target="_blank">david.screve@dlta-studio.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span style="white-space:pre-wrap">        </span>Hello TJ,</div><div><br></div><div><span style="white-space:pre-wrap">        </span>Actually not completely…Protocol does not handle properties storage. Only class (and struct) can be made abstract.</div><div><br></div><div><span style="white-space:pre-wrap">        </span>Doing this with protocol and class required the use of both and you need to enforce developer to inherit from class and implement protocol.. An abstract class encapsulate both on this in a single entity.</div>
<div><br></div><div><span style="white-space:pre-wrap">        </span>Here is a sample class for WebService : </div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">class</span> WebService {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">private</span> <span style="color:#bb2ca2">var</span> lastModified : <span style="color:#703daa">NSDate</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">var</span> url : <span style="color:#703daa">String</span>?</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">init</span>() {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="color:#000000"> </span>lastModified<span style="color:#000000">=</span><span style="color:#703daa">NSDate</span><span style="color:#000000">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"> <br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">func</span> performCall() {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#3d1d81">print</span>(<span style="color:#bb2ca2">self</span>.<span style="color:#4f8187">url</span>)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">self</span>.<span style="color:#4f8187">lastModified</span>=<span style="color:#703daa">NSDate</span>()</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</div></div><div><br></div><div>As written below, I can create a WebService instance…but I would like to forbid this because URL is a property that must be implemented by inherited classes.</div><div><br></div><div>I I use a protocol and Protocol extension, I will not be able to have lastModified stored value.</div><div><br></div><div>My proposal is to add abstract keyword as below : </div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">abstract <span style="color:#bb2ca2">class</span> WebService {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">private</span> <span style="color:#bb2ca2">var</span> lastModified : <span style="color:#703daa">NSDate</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> abstract <span style="color:#bb2ca2">var</span> url : <span style="color:#703daa">String</span>?</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">init</span>() {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="color:#000000"> </span>lastModified<span style="color:#000000">=</span><span style="color:#703daa">NSDate</span><span style="color:#000000">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"> <br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">func</span> performCall() {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#3d1d81">print</span>(<span style="color:#bb2ca2">self</span>.<span style="color:#4f8187">url</span>)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">self</span>.<span style="color:#4f8187">lastModified</span>=<span style="color:#703daa">NSDate</span>()</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</div></div><div><br></div><div>Then I will not be able to create a WebService object, and enforced to implement url property in inherited classes.</div><div><br></div><span style="white-space:pre-wrap">        </span>Regards,<div><br></div><div>David</div><div><div class="h5"><div><br><div><blockquote type="cite"><div>Le 4 déc. 2015 à 09:43, T.J. Usiyan <<a href="mailto:griotspeak@gmail.com" target="_blank">griotspeak@gmail.com</a>> a écrit :</div><br><div><div dir="ltr">Hello David,<div><br></div><div>This sounds like something that can be accomplished with protocols and default implementations provided in protocol extensions. If you've watched <a href="https://developer.apple.com/videos/play/wwdc2015-408/" target="_blank">Protocol-Oriented Programming in Swift [Session 408]</a>, slides 168 and on, once he begins talking about Protocol Extensions, is the relevant part. It looks like the functionality that you've described is already present in this feature.</div><div><br></div><div>TJ</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 4, 2015 at 3:30 AM, David Scrève <span dir="ltr"><<a href="mailto:david.screve@dlta-studio.com" target="_blank">david.screve@dlta-studio.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Hi Everyone,<br>
<br>
Nice to see this new swift-evolution process….I’m not sure to completely understand the whole process of requesting evolutions, but I’m trying<br>
to do…<br>
<br>
As I develop sort of framework, I usually have classes that I wanted to partially in the framework and force the user to implement others parts.<br>
<br>
For example, I have a WebService class that manage the whole process to perform asynchronous call, error management.<br>
This class has an abstract property that is specific for each WebService call.<br>
<br>
Then I would like to make the URL property abstract and, consequently, the whole WebService class abstract : The WebService cannot be directly instantiated.<br>
<br>
The goal of this feature would be to extend to method.<br>
This behavior already exists in Java and is really useful.<br>
<br>
The workaround is to make an URL property that returns invalid value or make assertion, but the error is only detected at runtime.<br>
<br>
My proposal would be to just add a keyword before func, class or var. An abstract property or func should not provide implementation.<br>
<br>
Regards,<br>
<br>
<br>
David<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>
</div></blockquote></div><br></div></div></div></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>