Strange, but C# does allow multiple inheritance, so long as it's serial

  • Thread starter Thread starter raylopez99
  • Start date Start date
I don't believe that I am, but understand your point. And I may have
gotten carried away in my description. I didn't mean to say that I use
them indiscriminately, I just meant that inheritance is incredibly
useful and to shun it--particularly for unspecified reason--is a little
bit crazy in the OO world.

Agreed. Just as crazy as overusing it :)

I regularly use interfaces, partly to make unit testing easier. It's
not *that* common for me to require an abstract base class, however.
I'm not saying it doesn't happen, but it's certainly not a daily
occurrence.

Jon
 
raylopez99 said:
Yes, and as they always say in textbooks, which leaves you guessing,
"that will be left as a programming exercise for the reader".

Yes. Well, C# interface inheritance certainly could mirror some C++
multiple inheritance code. One class inheriting from multiple "classes"
from the "layer" directly above (not one classe inheriting from multiple
layers above, one class at a time.)
Personally, I don't like inheritance, unless you need runtime
polymorphism using a base class reference. I don't like even single
inheritance, as it seems to be less flexible than a composition or
nested class. Everything is "HAS-A" but few things are "IS-A" it
seems to me.

Really? A car is a vehicle. A dog is an animal. I run into very many
examples.
BTW an excellent book--that I'm slowly working through--is this book
on class construction: "Design Patterns" by Gamma et al. (forward by
Grady Booch) (1977, 1995). You learn about cool classes like the
"Singleton", which by now is pretty well known, and other such
constructs.

That is a famous and influential book. But like many things that were the
original, there might be better, newer books to learn from.
 
There's one difference which can be really handy (and is completely
unrelated to true multiple inheritance): a nested class has access to
private members in its enclosing class. There are various situations
where that's incredibly useful.

Yes, I noticed this trick used in some code I was viewing the other
day now that you mention it. The nested class, to use C++
terminology, is a sort of "friend" of the enclosing class, with access
to all private variables and member functions of the enclosing class.
Nice trick, I'll make a note of this

RL
 
Back
Top