4 ms·
Well, off the top of my head C# doesn't support mixins or multiple inheritance. You can get around the lack of mixins with extension methods and tight scoping
by bigdubs 14y ago
Well, off the top of my head C# doesn't support mixins or multiple inheritance.
You can get around the lack of mixins with extension methods and tight scoping but it's messy.
- SeanLuke 14y ago> Well, off the top of my head C# doesn't support mixins or multiple inheritance. I was not aware that Smalltalk provided either.
- dfox 14y agoThere are libraries that add both of these features at once (either by defining new (meta)metaclasses or by simulating same effect through simple copying of methods from base classes.) On the other hand, Smalltalkers are quite keen on adding new methods to almost any existing system class, so mixins are not often as useful. Also Smalltalk development often relies on IDEs that do pretty extensive code generation behind the scenes and I think that this image based development with no real source code to speak of, and lots of reflection based development tools, is more important aspect of Smalltalk than any OO features.
- king_magic 14y agoC#'s (and Java's) lack of multiple inheritance is a virtue, IMO.
- bigdubs 14y agoI generally agree that use of mixins / multiple inheritance leads to architectural missteps.
- nnq 14y ago...aren't they completely different tools? One uses mixins to keep the class hierarchy shallow, with fewer levels of inheritance. OTOH multiple inheritance tends to complicate an overly convoluted class hierarchy most of the time. It's true that in a language like Python people use multiple inheritance to "simulate mixins", but it's to the same good effect of keeping the class hierarchy short and flat, but in C++ at least I've never seen MI used to simplify things, as opposed to mixins that always seem well used...
- amirrajan 14y agoThat is a false statement. dynamic C# 4.0 can do mixins: http://amirrajan.net/Blog/dynamic-c-sharp http://amirrajan.net/Blog/dynamic-c-sharp
- bigdubs 14y agoso, yes this leveraging of dynamic metadata provider technically satisfies the requirements for a mixin, but you're still not applying this mixin to a poco, therefore i don't think it's fair to say the language/spec supports it natively. this is another example of adding mixins to .net code via 3rd party library: http://remix.codeplex.com/ http://remix.codeplex.com/
- amirrajan 14y ago"but you're still not applying this mixin to a poco" Clarify?
- bigdubs 14y agoPOCO = Plain Old (CLR) Object The distinction I'm drawing here is what is meant by 'natively supports' and 'supported via a 3rd party library'
- amirrajan 14y agoThat's what I need clarification on. the dynamic keyword wasn't provided by any 3rd party library (it's part of the C# language specification)... how is System.DynamicObject and IDynamicMetaObjectProvider different then System.Object? All poco's inherit System.Object. Do you consider System.Object as 3rd party? True, by default poco's don't inherit from System.DynamiObject. Does that make it not 'natively supported'?
- bigdubs 14y agoNo, what I mean by that is in order to use mixins, in any example I've seen, you need to inherit from a class someone else provided that gives it. Assembly provides all the mechanisms for the dynamic keyword, I wouldn't say it is a feature of x86.