7 ms·
I used to be like this before I realized I used class inheritance way too much and shifted to using composition in the majority of cases.
by droidist2 13y ago
I used to be like this before I realized I used class inheritance way too much and shifted to using composition in the majority of cases.
- voltagex_ 13y agoWhere's the best place to brush up on composition vs inheritance?
- profquail 13y agoIf you're familiar with C#, Real World Functional Programming: With Examples in F# and C# [1] is an excellent resource for learning how and when to use composition over inheritance. [1]: http://www.amazon.com/Real-World-Functional-Programming-With-Examples/dp/1933988924 http://www.amazon.com/Real-World-Functional-Programming-With...
- voltagex_ 13y agoI thought composition vs inheritance was strictly an OO, not a functional thing?
- profquail 13y agoFunctional programming usually leans towards composition, and OO programming towards inheritance. "Hybrid" functional languages, like F# and Scala, allow you to use both styles, mixing them in whatever way is most useful for the particular problem you're solving; "pure" functional languages, like Haskell don't offer OO-style inheritance, since composition is a better fit for combining side-effect free ("pure") functions. tl;dr -- Composition is to functional programming as inheritance is to OO programming.
- voltagex_ 13y agoYeesh, $40 for the ePub directly from Manning, or $33 from Amazon for the print edition with a free ePub.
- profquail 13y agoThere are a few chapters of the book online for free at MSDN, and if you're going to buy the book, they also have a coupon code: http://msdn.microsoft.com/en-us/library/vstudio/hh314518%28v=vs.100%29.aspx http://msdn.microsoft.com/en-us/library/vstudio/hh314518%28v...
- _random_ 13y agoI agree, any tool must be used correctly.
- eonil 13y agoAnd .NET framework tend to overuse subclassing/overriding pattern where delegation is more appropriate. That frequently leads users also overuse subclassing/overriding.
- novaleaf 13y ago++ this, I moved from C# to Typescript and see that pattern change as being the biggest difference as to the code style i write. I started Typescript by subclassing but as I work more and more with it, I subclass less and less, and delegate more and more.