<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On 26 January 2016 at 13:10, Craig R Webster <span dir="ltr"><<a href="mailto:craig@xeriom.net" target="_blank">craig@xeriom.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If you did it this way Tempfile would no longer have the same interface as File. The constructor signature has changed so I think you’d be violating the Liskov substitution principle. If Tempfile IS-A File then I should be able to use it in place of File in any code that uses File.</blockquote></div><br>What you're describing here isn't a violation of the Liskov substitution principle because an instance of Tempfile still substitutes for an instance of File, the signature of the constructor is not relevant to code that interacts with instances of those classes after instantiation.</div><div class="gmail_extra"><br></div><div class="gmail_extra">If however you had an object of class FileFactory, with instance method `#create`, that created instances of File and you wanted to subclass that (TempFileFactory) to produce instances of TempFile then it would be useful if you could substitute one for the other. Again Liskov's principle wouldn't apply to the constructors of those factory objects, but only to their `#create` method.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Inheritance is, in my experience, over used due its convenience so I usually find myself arguing against it.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Composition brings the cost of extra code necessary to compose collaborating objects together but results in those objects each being simpler, more flexible and reusable.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Inheritance on the other hand is very convenient and produces a static structure that is often appealing. The downside is its tendency to result in complex objects that are difficult to work with. ActiveRecord for example uses multiple inheritance and exposes 400+ instance methods to a subclass before its own methods are added.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div><div class="gmail_signature"><div dir="ltr"><br><div>Bestie.</div><div><br></div><div><a href="http://theaudaciouscodeexperiment.com" target="_blank">theaudaciouscodeexperiment.com</a><br><a href="http://github.com/bestie" target="_blank">github.com/bestie</a><br>@thebestie</div></div></div></div>
</div></div>