Inherit seems to good to be true

Is there any downfall to inheriting a class instead of the class being passed around  in the New() sub
Who is Participating?
Mike TomlinsonMiddle School Assistant TeacherCommented:
Take the Delegates out of the Class then...

Just make the Class raise events that notify the GUI of what is happening and to pass data out.

Let the FORM store and make the Delegates since it needs to update itself.

See this ridiculous example I came up with here:
It would depend on what you where planning on doing, you're question is a bit vague btw.  Lobbing objects around is all good and well, but at the end of the day it will make your code messy and harder to debug.  Encapsulating certain basic functions and core tasks in base classes which get inherited makes the code neater and in the long run easier to maintain, also there would probably be less memory usage at the end of the day although the difference would probably be negligible unless the developer habitually did not clean up after himself.  If say for example you had a base class which would save and retrieve certain settings in the registry, then the inheriting class using this base class decides it wants to write an extra setting to the registry can override the base class method and write the extra setting into the registry before invoking the base classes registry update.  Trying stuff like that without inheritance etc. gets really messy after a while.  The key IMHO is determining what needs to go into the base class's.
I'm not sure I understand the question.  But, so far as I do, the answer is "I don't think so".

You have a class called Widget.  You want some Black Widgets and some White Widgets.

Scenario A: you inherit from Widget into (1) BlackWidget and (2) WhiteWidget - hardcoding the appropriate, different color into each.

Scenario B: you code the New() method of Widget to accept a color argument and call New(Black) when you want BlackWidgets and New(White) when you want WhiteWidgets

Scenario C: you give your Widget class a Color property and, having created an instance of it with New you then call
   myWidget.Color = Black
   myWidget.Color = White

Whichever way you do it, each instance of the class/es is a separate object.  So, at this level anyway, I can't see what sort of "downfall" there might be.

What sort of thing did you have in mind?

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Inheritance only makes sense when the DERIVED class (that which is INHERITING from the base class) has an "IS A" relationship to the base class.

Consider a Base class MAMMAL and a derived Class DOG ( clear a DOG 'IS A' MAMMAL).   In this case, Inheritance makes a lot of sense, since much of the nature of the DOG class can be placed in the MAMMAL class, and only those aspects that make a DOG a DOG (and are different from say a PERSON - a PERSON is also a MAMMAL, but quite different froma DOG - for one thing , a PERSON has 2 legs, while a DOG has 4 legs).

But it would make abosolutely no sense whatsoever to try to create a BATTLESHIP class that inherits from a MAMMAL class - clearly a BATTLESHIP has absolutley nothing in common with a MAMMAL.

Bob LearnedCommented:
Yeah, I'll jump on the bandwagon and say that this question doesn't make any sense :(

Mike TomlinsonMiddle School Assistant TeacherCommented:
I think he wants to access values from one class, inside another class, and has discovered that if you inherit from the first class then you can access them.

The purpose of the question would then be for us to contrast that approach with simply passing a reference to the first class into the second and list advantages/disadvantages of each.
Bob LearnedCommented:
Hi, Mike, you must be a mind reader, or maybe you helped with a different question that would give you important insights here ;)

HepenAuthor Commented:
I have a class that performs asynchronous TCP.  Within those async TCP threads I have to use delegates in order to get data out of the thread and into my form.  I have so many delegates now that it is taking up a lot of space in my class.  Now I just made a seperate class called clsFormDelegates and I Inherit it when I need to use the delegates to get data from a thread into my form.

Is this the correct usage of Inheriting?
HepenAuthor Commented:
What if I were to just create an instance of clsFormDelegates and call each method like:


Or if I inherited


If I inherit it looks as if the above methods are part of the class which could throw some of my team members off.  They will be like where did these methods come from? Oh you inherited them? I see.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.