473,324 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

not inherit property

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
7 1736
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
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
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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Christian Dieterich | last post by:
Hi, I need to create many instances of a class D that inherits from a class B. Since the constructor of B is expensive I'd like to execute it only if it's really unavoidable. Below is an example...
7
by: Fabian Neumann | last post by:
Hi! I got a problem with font-family inheritance. Let's say I have CSS definitions like: p { font:normal 10pt Verdana; } strong { font:normal 14pt inherit;
3
by: Gabe Moothart | last post by:
I would like to create slightly modified 'custom' data types. For instance, a 'Degree' type, which behaves exactly like a double, except that it has an extra property 'ToRadians'. Or, a 'phone'...
6
by: Mohammad-Reza | last post by:
I wrote a component using class library wizard. In my component i want to in order to RightToLeft property do some works. I can find out if user set this property to Yes or No, But if He/She set it...
6
by: Charlie | last post by:
Hi: The code to add items to shopping cart is a seperate class file so I don't have to keep repeating it. If I want to be able to access session data in this class, which class should I base it...
8
by: Issac | last post by:
Hi, I created an Inherit UserControl which inherits textbox with additional property say 'Type'. I used in my forms and everything works fine. But afterward, I want to remove (or rename) such...
0
by: Frank | last post by:
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....
7
by: libsfan01 | last post by:
Hi all This js i wrote to switch display on and off of a given element does not work in ie but it does in ff and safari. how can i make it work with ie guys? <script...
2
by: GTalbot | last post by:
Hello fellow comp.infosystems.www.authoring.stylesheets colleagues, Imagine this situation: #grand-parent-abs-pos { height: 400px; position: absolute; width: 600px; }
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.