<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>Overriding is not normally how you test classes to begin with.<br></div>
<div> </div>
<div>The traditional Obj-C way of testing classes like that is to use a mocking library, that provides NSProxy objects that forward non-stubbed methods to the original class (or forward everything and merely record which methods were invoked). This of course only works for classes that use the Obj-C runtime.<br></div>
<div> </div>
<div>The approach that is often recommended for Swift is to use protocol-oriented programming, where you expose things as protocols instead of as classes. That way you can provide your own implementation of the protocol in order to mock something out.<br></div>
<div> </div>
<div>-Kevin Ballard</div>
<div> </div>
<div>On Mon, Dec 21, 2015, at 09:35 AM, Tomáš Linhart via swift-evolution wrote:<br></div>
<blockquote type="cite"><div dir="ltr"><div>But tell me how will you test your code that is depending on a class provided by external party? You cannot subclass so you cannot override the behaviour that you need stub, at the you will wrap entire library in your own classes that you can subclass but what for? Subclassing rarely breaks things and if it does, you should mark it final but it shouldn't be explicit.<br></div>
<div> </div>
<div><div>Tomáš <br></div>
<div><div> </div>
<div><div>On Mon, Dec 21, 2015 at 6:31 PM, Javier Soto <span dir="ltr"><<a href="mailto:javier.api@gmail.com">javier.api@gmail.com</a>></span> wrote:<br></div>
<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204, 204, 204);border-left-style:solid;padding-left:1ex;"><div>I think it's just as important for methods. If you make a class final, all methods become final, so that's OK. But if you make a class subclassable, and then forget to mark some of it's methods final, then all methods would be overridable which is probably not what you'd want in must cases. <br></div>
<div><div><div><div dir="ltr">On Mon, Dec 21, 2015 at 9:19 AM Tomáš Linhart <<a href="mailto:tomas@linhart.me">tomas@linhart.me</a>> wrote:<br></div>
<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204, 204, 204);border-left-style:solid;padding-left:1ex;"><div dir="ltr"><div><div>Hello,<br></div>
<div> </div>
<div>I must say, I am not big fun of this proposal because currently in Swift only way how to mock classes is to subclass them. If this proposal becomes reality, it will make mocking of all third-party libraries impossible unless they mark their classes non-final and I am afraid authors will just use the default behaviour so at the end people will stop testing code that is using third-party libraries or they will have to fork the libraries or ask the authors. This can be fixed by having better testing support in Swift but I don't think, this will happen anytime soon.<br></div>
<div> </div>
<div>I would rather see introduction of better reflection so mock frameworks can be reality. I would like to see also other building block of objected-oriented-programming such as abstract classes, protocols with generic type parameters and not just abstract types (associated types) that allows to design better APIs that don't depend so much on overriding regular classes.<br></div>
<div> </div>
<div> </div>
<div><span><span class="colour" style="color:rgb(136, 136, 136)">Tomáš</span></span><br></div>
<div> </div>
</div>
</div>
</blockquote></div>
</div>
</div>
<div> </div>
<div dir="ltr"><span><span class="colour" style="color:rgb(136, 136, 136)">-- </span></span><br></div>
<div><span><span class="colour" style="color:rgb(136, 136, 136)">Javier Soto
</span></span><br></div>
</blockquote></div>
</div>
</div>
</div>
<div><img style="height:1px !important;width:1px !important;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;border-left-width:0px !important;margin-top:0px !important;margin-bottom:0px !important;margin-right:0px !important;margin-left:0px !important;padding-top:0px !important;padding-bottom:0px !important;padding-right:0px !important;padding-left:0px !important;" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/bea71011a7367a9e9e944669eb73180f4242e17f5d9cbe9c9652f819878d5d61/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d3148765176786c673171614a7d2236454230345272776e415143563c657b42607a663746584e647e4e4375534354594f6a5e445772755e484b45734238464f6b643059646c454560796a705a4d2236423846415447613244425741455859673d2236495a52766c6a4c4148615976673d685e6a543d444e42555b66613d4a516243437848443f4c41317377783773796b444c43537c68736674616333584a643a65483334316579554d6a714356484336615c64514231673276354d22324c605163776d22364767747a57386b67413762346e6a49527b4073513f476d2232415642376d23344d23344/open"><br></div>
<div><u>_______________________________________________</u><br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</blockquote><div> </div>
</body>
</html>