By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

not inherit property

P: n/a
Hi, a question probably asked before, but I can't find the answers.
Base class X, classes A, B and C inherit class X.
In class A I do not want to inherit property (or function or method) P1.
Possible? How?
Thanks in advance
Frank


Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Frank,
If A does not have a P1, but B & C do, then I would recommend you reevaluate
your object model. As it really sounds like A inherits from X, while B & C
inherits from Y, where Y inherits from X and Y has a P1.

Something like:

Public MustInherit Class X

End Class

Public MustInherit Class Y

Public Sub P1()

End Sub

End Class

Public Class A : Inherits X

End Class

Public Class B : Inherits Y

End Class

Public Class C : Inherits Y

End Class

Remember when Class A inherits X, you are stating that A *is a* X, every
place an X can be used an A can be used, which means that A has to have
every thing that an X has!

Hope this helps
Jay

"Frank" <fr***@frank.com> wrote in message
news:ce**********@news1.tilbu1.nb.home.nl...
Hi, a question probably asked before, but I can't find the answers.
Base class X, classes A, B and C inherit class X.
In class A I do not want to inherit property (or function or method) P1.
Possible? How?
Thanks in advance
Frank

Nov 20 '05 #2

P: n/a
Jay,
it's a possibility. But if I need 100 props that are needed by A, B and C,
and only one of those 100 is not needed by A. Then it's more efficient to
remove that one from A. Isn't it?
Frank

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eu**************@TK2MSFTNGP11.phx.gbl...
Frank,
If A does not have a P1, but B & C do, then I would recommend you reevaluate your object model. As it really sounds like A inherits from X, while B & C
inherits from Y, where Y inherits from X and Y has a P1.

Something like:

Public MustInherit Class X

End Class

Public MustInherit Class Y

Public Sub P1()

End Sub

End Class

Public Class A : Inherits X

End Class

Public Class B : Inherits Y

End Class

Public Class C : Inherits Y

End Class

Remember when Class A inherits X, you are stating that A *is a* X, every
place an X can be used an A can be used, which means that A has to have
every thing that an X has!

Hope this helps
Jay

"Frank" <fr***@frank.com> wrote in message
news:ce**********@news1.tilbu1.nb.home.nl...
Hi, a question probably asked before, but I can't find the answers.
Base class X, classes A, B and C inherit class X.
In class A I do not want to inherit property (or function or method) P1.
Possible? How?
Thanks in advance
Frank


Nov 20 '05 #3

P: n/a
Frank,
As I stated:
Remember when Class A inherits X, you are stating that A *is a* X, every
place an X can be used an A can be used, which means that A has to have
every thing that an X has! Wanting to remove P1 from X is stating A *IS NOT A* X.

Which is it, is A an X or Not?

As I stated you cannot remove a member from a class, if you "removed" P1
from A, what do you expect the following code to do?

Dim anX As X
anX = New A

anX.P1

Remember that X has a P1, A inherits from X so you can assign an A object to
an X variable. Because you have an X variable you can call P1, however you
firmly insist that P1 does not exist on A. Yet the above code is calling P1
on A. What do you expect to happen? I am attempting to tell you what will
happen & why.

If the second base class causes polymorphism problems, I would consider
making P1 overridable, and override the method in A and simply throw a
NotSupportedException.

Something like: Public MustInherit Class X
Public Overridable Sub P1()
End Sub
End Class Public Class A : Inherits X
Public Overrides Sub P1()
Throw New NotSupportedException()
End Sub
End Class
Then it's more efficient to
remove that one from A. Isn't it?
Introducing a second base class does not cause any "efficiency" problems.

I find it better to write "correct" programs then to worry about "what is
optimized". By "correct" I mean OO and use the correct tool for the correct
job (for example: when to add a second base class & when not to). Remember
that most programs follow the 80/20 rule (link below) that is 80% of the
execution time of your program is spent in 20% of your code. I will optimize
the 20% once that 20% has been identified & proven to be a performance
problem via profiling (see CLR Profiler in my other message).

For info on the 80/20 rule & optimizing only the 20% see Martin Fowler's
article "Yet Another Optimization Article" at
http://martinfowler.com/ieeeSoftware...timization.pdf

Hope this helps
Jay

"Frank" <fr***@frank.com> wrote in message
news:ce**********@news1.tilbu1.nb.home.nl... Jay,
it's a possibility. But if I need 100 props that are needed by A, B and C,
and only one of those 100 is not needed by A. Then it's more efficient to
remove that one from A. Isn't it?
Frank

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eu**************@TK2MSFTNGP11.phx.gbl...
Frank,
If A does not have a P1, but B & C do, then I would recommend you

reevaluate
your object model. As it really sounds like A inherits from X, while B &

C inherits from Y, where Y inherits from X and Y has a P1.

Something like:

Public MustInherit Class X

End Class

Public MustInherit Class Y

Public Sub P1()

End Sub

End Class

Public Class A : Inherits X

End Class

Public Class B : Inherits Y

End Class

Public Class C : Inherits Y

End Class

Remember when Class A inherits X, you are stating that A *is a* X, every
place an X can be used an A can be used, which means that A has to have
every thing that an X has!

Hope this helps
Jay

"Frank" <fr***@frank.com> wrote in message
news:ce**********@news1.tilbu1.nb.home.nl...
Hi, a question probably asked before, but I can't find the answers.
Base class X, classes A, B and C inherit class X.
In class A I do not want to inherit property (or function or method) P1. Possible? How?
Thanks in advance
Frank



Nov 20 '05 #4

P: n/a
Jay,
so I guess it is not possbile to remove a property.

On the efficiency: I mean the work I have to type all the stuff into the
classes.
X with 10 properties.
A,B and C inherit from X.
But A does not need prop P1.
Meaning I have to introduce Class Y with 9 props.
Then I have to type 9 props (and methods and functions....) twice. U could
copy them. Ok, I would do that. But what about maintenance and forgetting X
and Y are almost the same and a change has to be done in both classes?
On the other hand I can have class X with 9 props and put P1 in B and C.
Thats nice for 1 prop, but what if u have dozens? And then I have 2 exactly
the same props and could forget to maintain them one of them.
I guess I will have to resort to your suggestion about
NotSupportedException.
Regards .
Frank

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uF**************@TK2MSFTNGP10.phx.gbl...
Frank,
As I stated:
Remember when Class A inherits X, you are stating that A *is a* X, every place an X can be used an A can be used, which means that A has to have every thing that an X has! Wanting to remove P1 from X is stating A *IS NOT A* X.

Which is it, is A an X or Not?

As I stated you cannot remove a member from a class, if you "removed" P1
from A, what do you expect the following code to do?

Dim anX As X
anX = New A

anX.P1

Remember that X has a P1, A inherits from X so you can assign an A object to an X variable. Because you have an X variable you can call P1, however you
firmly insist that P1 does not exist on A. Yet the above code is calling P1 on A. What do you expect to happen? I am attempting to tell you what will
happen & why.

If the second base class causes polymorphism problems, I would consider
making P1 overridable, and override the method in A and simply throw a
NotSupportedException.

Something like: Public MustInherit Class X
Public Overridable Sub P1()
End Sub
End Class Public Class A : Inherits X
Public Overrides Sub P1()
Throw New NotSupportedException()
End Sub
End Class
Then it's more efficient to
remove that one from A. Isn't it?
Introducing a second base class does not cause any "efficiency" problems.

I find it better to write "correct" programs then to worry about "what is
optimized". By "correct" I mean OO and use the correct tool for the

correct job (for example: when to add a second base class & when not to). Remember
that most programs follow the 80/20 rule (link below) that is 80% of the
execution time of your program is spent in 20% of your code. I will optimize the 20% once that 20% has been identified & proven to be a performance
problem via profiling (see CLR Profiler in my other message).

For info on the 80/20 rule & optimizing only the 20% see Martin Fowler's
article "Yet Another Optimization Article" at
http://martinfowler.com/ieeeSoftware...timization.pdf

Hope this helps
Jay

"Frank" <fr***@frank.com> wrote in message
news:ce**********@news1.tilbu1.nb.home.nl...
Jay,
it's a possibility. But if I need 100 props that are needed by A, B and C, and only one of those 100 is not needed by A. Then it's more efficient to remove that one from A. Isn't it?
Frank

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:eu**************@TK2MSFTNGP11.phx.gbl...
Frank,
If A does not have a P1, but B & C do, then I would recommend you reevaluate
your object model. As it really sounds like A inherits from X, while B & C inherits from Y, where Y inherits from X and Y has a P1.

Something like:

Public MustInherit Class X

End Class

Public MustInherit Class Y

Public Sub P1()

End Sub

End Class

Public Class A : Inherits X

End Class

Public Class B : Inherits Y

End Class

Public Class C : Inherits Y

End Class

Remember when Class A inherits X, you are stating that A *is a* X,
every place an X can be used an A can be used, which means that A has to have every thing that an X has!

Hope this helps
Jay

"Frank" <fr***@frank.com> wrote in message
news:ce**********@news1.tilbu1.nb.home.nl...
> Hi, a question probably asked before, but I can't find the answers.
> Base class X, classes A, B and C inherit class X.
> In class A I do not want to inherit property (or function or method)

P1. > Possible? How?
> Thanks in advance
> Frank
>
>
>
>



Nov 20 '05 #5

P: n/a
"Frank" <fr***@frank.com> wrote in message
news:ce**********@news5.tilbu1.nb.home.nl...
Jay,
so I guess it is not possbile to remove a property.


It's not very easy, no. And not particularly desirable, as Jay states. You
can take the MS approach, and just have it do nothing (or affect nothing) in
the one class which does not need the implementation.

Best Regards,

Andy
Nov 20 '05 #6

P: n/a
Frank,
On the efficiency: I mean the work I have to type all the stuff into the There is NO efficiency problems! No duplicate typing!!

Please look closer at my original response!
X with 10 properties.
X has 9 properties

Y has 1 property, Y inherits from X
A,B and C inherit from X.
B & C inherit from Y, again Y inherits from X

A inherits from X
Meaning I have to introduce Class Y with 9 props.
No Y only needs the props that A does not have!
Then I have to type 9 props (and methods and functions....) twice. U could
copy them. Ok, I would do that. But what about maintenance and forgetting X
There is NO cut & paste programming needed! No duplication of code, no
maintenance problems!

Remember you *CAN* have more then one base class by layering one base class
from a second base class. In your case X has the 9 common members, Y has the
1 common member. Y inherits from X to gain the other 9 common members. A
only needed the 9 inherits from X. B & C needing all ten inherit from Y
which give then all 10. There is NO duplication of code. Neat clean object
oriented design!

Something like:

Public MustInherit Class X

Public Sub P2()

End Sub

Public Sub P3()

End Sub

Public Sub P4()

End Sub

Public Sub P5()

End Sub

Public Sub P6()

End Sub

Public Sub P7()

End Sub

Public Sub P8()

End Sub

Public Sub P9()

End Sub

Public Sub P10()

End Sub

End Class

Public Class A : Inherits X

End Class

Public MustInherit Class Y

Public Sub P1()

End Sub

End Class

Public Class B : Inherits Y

End Class

Public Class C : Inherits Y

End Class
Hope this helps
Jay


"Frank" <fr***@frank.com> wrote in message
news:ce**********@news5.tilbu1.nb.home.nl... Jay,
so I guess it is not possbile to remove a property.

On the efficiency: I mean the work I have to type all the stuff into the
classes.
X with 10 properties.
A,B and C inherit from X.
But A does not need prop P1.
Meaning I have to introduce Class Y with 9 props.
Then I have to type 9 props (and methods and functions....) twice. U could
copy them. Ok, I would do that. But what about maintenance and forgetting X and Y are almost the same and a change has to be done in both classes?
On the other hand I can have class X with 9 props and put P1 in B and C.
Thats nice for 1 prop, but what if u have dozens? And then I have 2 exactly the same props and could forget to maintain them one of them.
I guess I will have to resort to your suggestion about
NotSupportedException.
Regards .
Frank

<<snip>>
Nov 20 '05 #7

P: n/a
Ok, I understand what u mean. I'll look into it.
Thanks for your time
Frank
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
Frank,
On the efficiency: I mean the work I have to type all the stuff into the There is NO efficiency problems! No duplicate typing!!

Please look closer at my original response!
X with 10 properties.


X has 9 properties

Y has 1 property, Y inherits from X
A,B and C inherit from X.


B & C inherit from Y, again Y inherits from X

A inherits from X
Meaning I have to introduce Class Y with 9 props.


No Y only needs the props that A does not have!
Then I have to type 9 props (and methods and functions....) twice. U could copy them. Ok, I would do that. But what about maintenance and forgetting X
There is NO cut & paste programming needed! No duplication of code, no
maintenance problems!

Remember you *CAN* have more then one base class by layering one base class from a second base class. In your case X has the 9 common members, Y has the 1 common member. Y inherits from X to gain the other 9 common members. A
only needed the 9 inherits from X. B & C needing all ten inherit from Y
which give then all 10. There is NO duplication of code. Neat clean object
oriented design!

Something like:

Public MustInherit Class X

Public Sub P2()

End Sub

Public Sub P3()

End Sub

Public Sub P4()

End Sub

Public Sub P5()

End Sub

Public Sub P6()

End Sub

Public Sub P7()

End Sub

Public Sub P8()

End Sub

Public Sub P9()

End Sub

Public Sub P10()

End Sub

End Class

Public Class A : Inherits X

End Class

Public MustInherit Class Y

Public Sub P1()

End Sub

End Class

Public Class B : Inherits Y

End Class

Public Class C : Inherits Y

End Class
Hope this helps
Jay


"Frank" <fr***@frank.com> wrote in message
news:ce**********@news5.tilbu1.nb.home.nl...
Jay,
so I guess it is not possbile to remove a property.

On the efficiency: I mean the work I have to type all the stuff into the
classes.
X with 10 properties.
A,B and C inherit from X.
But A does not need prop P1.
Meaning I have to introduce Class Y with 9 props.
Then I have to type 9 props (and methods and functions....) twice. U
could copy them. Ok, I would do that. But what about maintenance and

forgetting X
and Y are almost the same and a change has to be done in both classes?
On the other hand I can have class X with 9 props and put P1 in B and C.
Thats nice for 1 prop, but what if u have dozens? And then I have 2

exactly
the same props and could forget to maintain them one of them.
I guess I will have to resort to your suggestion about
NotSupportedException.
Regards .
Frank

<<snip>>

Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.