Class inherit issues 
Author Message
 Class inherit issues

Hi,

I'm having a problem with class inherit in VB.Net, that a base class
contains several public attributes, say attributeA, attributeB and
attributeC, and there are other two classes (say classA and classB) inherit
this base class, but classA just need attributeA and attributeB, and classB
just need attributeB and attributeC, is there any way I can do that other
than I have to create two separated base classes? (As I know C++ is able to
do that)

Thanks for any feedback.

Michael



Tue, 31 Aug 2004 02:28:22 GMT  
 Class inherit issues
First problem with your solution.

DONT USE PUBLIC ATTRIBUTES!

Was that loud enuf :-) It's poor OO design (breaks encapsulation). Use
private (or protected) attributes and expose them with properties or
functions, only exposing the ones you need. I suspect you need to set these
values from outside the class so a property would be appropriate. The
property can also validate your new values before setting them.

Secondly.

Everybody on first contact with OO always seem to jump on the inheritance
bandwagon :-) As a rule of thumb, always consider whether an interface or 2
may in fact be the solution to a problem rather than inheritance.

You clearly have two different interfaces and a single class implementing
them both.

Hope that helps.


Quote:
> Hi,

> I'm having a problem with class inherit in VB.Net, that a base class
> contains several public attributes, say attributeA, attributeB and
> attributeC, and there are other two classes (say classA and classB)
inherit
> this base class, but classA just need attributeA and attributeB, and
classB
> just need attributeB and attributeC, is there any way I can do that other
> than I have to create two separated base classes? (As I know C++ is able
to
> do that)

> Thanks for any feedback.

> Michael



Tue, 31 Aug 2004 02:40:44 GMT  
 Class inherit issues
Thanks a lots for the suggestion.

Michael


Quote:
> First problem with your solution.

> DONT USE PUBLIC ATTRIBUTES!

> Was that loud enuf :-) It's poor OO design (breaks encapsulation). Use
> private (or protected) attributes and expose them with properties or
> functions, only exposing the ones you need. I suspect you need to set
these
> values from outside the class so a property would be appropriate. The
> property can also validate your new values before setting them.

> Secondly.

> Everybody on first contact with OO always seem to jump on the inheritance
> bandwagon :-) As a rule of thumb, always consider whether an interface or
2
> may in fact be the solution to a problem rather than inheritance.

> You clearly have two different interfaces and a single class implementing
> them both.

> Hope that helps.



> > Hi,

> > I'm having a problem with class inherit in VB.Net, that a base class
> > contains several public attributes, say attributeA, attributeB and
> > attributeC, and there are other two classes (say classA and classB)
> inherit
> > this base class, but classA just need attributeA and attributeB, and
> classB
> > just need attributeB and attributeC, is there any way I can do that
other
> > than I have to create two separated base classes? (As I know C++ is able
> to
> > do that)

> > Thanks for any feedback.

> > Michael



Tue, 31 Aug 2004 04:07:25 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problem with a vb.Net class inheriting from a c# class

2. nested class inherits containing class accessing private instance members

3. Inherited controls performance issues?

4. Identifying Inherited Classes Properties and Methods seperately form inheriting classes P's and M's

5. DataGrid remove item error bind with own class inherit from collection

6. DataGrid remove item error bind with own class inherit from collection

7. Hide property in inherited class?

8. Returning a collection class (inherited from CollectionBase) via webService

9. Custom inherited class...

10. Inheriting the commondialog class in Vb.net

11. two inherits in one class

12. Inherit WSDL generated vb into COM class

 

 
Powered by phpBB® Forum Software