3 ms·
Inheritance is just a total mess. Overriding a method, especially a non-abstract one, feels more like monkeypatching. It feels unsafe, it's not clear if I shoul
by bowsamic 4y ago
Inheritance is just a total mess. Overriding a method, especially a non-abstract one, feels more like monkeypatching. It feels unsafe, it's not clear if I should do it, etc. A lot of Apple APIs mark which methods should be overridden and which shouldn't be. It just generally feels like a crappy approach. Languages with deep inheritance trees like Ruby and Smalltalk and even Objective-C are also extremely difficult to learn how to use due to how much basic functionality of the object comes from far up the chain. Remember when Steve Jobs wanted people to make companies that just sell objects? Sounds like my worst nightmare. I don't see why Rust's dynamic traits, or just duck typing, aren't totally superior
- fabian2k 4y agoThe user you responded to uses C#, you can't override arbitrary methods there. Only methods explicity declared as virtual can be overriden, so this is different than many other OO languages. I think this is also the better approach, making inheritance something you have to explicitly design for instead of a way to monkeypatch almost everything.
- smcl 4y ago> Only methods explicity declared as virtual can be overriden You can with "new", no? public class Foo { public void Say() { Console.WriteLine("Foo!"); } public void Think() { Console.WriteLine("I;m thinkin about thos beans"); } public class Bar : Foo { new public void Say() { Console.WriteLine("Actually, Bar!"); } } So with Bar we have inherited Think(), but have overridden Say(). Ok technically the MSDN docs will say that we've "hidden" the inherited method Say(), but the effect here is that we've overridden something not marked "virtual" edit: Oops yeah I'm talking rubbish, see replies for more info :D
- fabian2k 4y agoUsing new is still very different from using override, there are real differences in behaviour there. Though I never used "new", it's usually described as a really bad idea unless you know what you're doing, I never saw the need to use this.
- bartwe 4y agoIsn't that shadowing instead of inheritance ?
- A321321 4y agoNo, that’s not how new works. Any method in the base class will still call the “hidden” method. https://dotnetfiddle.net/zcVPof https://dotnetfiddle.net/zcVPof
- smcl 4y agoAh yeah you're right :)
- bowsamic 4y agoWow that's very interesting, and much better