473,399 Members | 4,177 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,399 software developers and data experts.

Hiding an inherited method/property

Back again...

I have some classes that inherit from each other, as an example...

Point (abstract base class)

Point3 (for 3D points), derived from Point

Point4 (adds a homogenous co-ordinate) derived from Point3

Point3 has a Method - MoveBy(float dx, float dy, float dz), for moving it
relatively in 3D space.

Point4 has its own equivalent - MoveBy(float dx, float dy, float dz, float
dw), but I want to hide Point3's MoveBy, so it isn't available when you are
working with a Point4. There are other methods/properties of Point3 that
still make sense for Point4, so I don't want to love all the inherited
methods/properties.

Hope this makes sense, and thanks for all your help,

Yours,

Ann-Marie Ratcliffe

Nov 15 '05 #1
4 3735
A Ratcliffe <ar********@archiNOSPAMmagic.net> wrote:
I have some classes that inherit from each other, as an example...

Point (abstract base class)

Point3 (for 3D points), derived from Point

Point4 (adds a homogenous co-ordinate) derived from Point3

Point3 has a Method - MoveBy(float dx, float dy, float dz), for moving it
relatively in 3D space.

Point4 has its own equivalent - MoveBy(float dx, float dy, float dz, float
dw), but I want to hide Point3's MoveBy, so it isn't available when you are
working with a Point4. There are other methods/properties of Point3 that
still make sense for Point4, so I don't want to love all the inherited
methods/properties.


It sounds like your Point4 shouldn't be derived from a Point3 - it
breaks Liskov's Substitutability Principle (namely that whatever you
can do with a Point3, you should be able to do with a Point4).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
"Jon Skeet [C# MVP]" wrote

It sounds like your Point4 shouldn't be derived from a Point3 - it
breaks Liskov's Substitutability Principle (namely that whatever you
can do with a Point3, you should be able to do with a Point4).


Looks like you are right on that basis. Actually, these are 'helper'
functions for the individual classes. Everything else works correctly, but
these are just meant to provide a quicker way of moving/setting the points
than individually setting the co-ords.

On that basis, they could be removed and I wouldn't have this problem. But
Helper functions/methods are developer-friendly...

Thanks for your help,

Ann-Marie
Nov 15 '05 #3
If it makes sense, you might make a MoveBy(dx, dy,dz) in Point 4 that
calls the 4 argument version with dw=0. That way Point4 is logically related
to Point3. [Perhaps that makes no sense in your case, but it's worth
considering]
Bob
"A Ratcliffe" <ar********@archiNOSPAMmagic.net> wrote in message
news:OF**************@TK2MSFTNGP09.phx.gbl...
Back again...

I have some classes that inherit from each other, as an example...

Point (abstract base class)

Point3 (for 3D points), derived from Point

Point4 (adds a homogenous co-ordinate) derived from Point3

Point3 has a Method - MoveBy(float dx, float dy, float dz), for moving it
relatively in 3D space.

Point4 has its own equivalent - MoveBy(float dx, float dy, float dz, float
dw), but I want to hide Point3's MoveBy, so it isn't available when you are working with a Point4. There are other methods/properties of Point3 that
still make sense for Point4, so I don't want to love all the inherited
methods/properties.

Hope this makes sense, and thanks for all your help,

Yours,

Ann-Marie Ratcliffe

Nov 15 '05 #4
Mon, 3 Nov 2003 12:46:13 -0000, on
microsoft.public.dotnet.languages.csharp, A Ratcliffe wrote:

[...]
Point3 has a Method - MoveBy(float dx, float dy, float dz), for moving it
relatively in 3D space.

Point4 has its own equivalent - MoveBy(float dx, float dy, float dz, float
dw), but I want to hide Point3's MoveBy, so it isn't available when you are
working with a Point4. There are other methods/properties of Point3 that
still make sense for Point4, so I don't want to love all the inherited
methods/properties.

[...]

Hi
If I've understood correctly, the "new" keyword should be the cure for your
problem :)
In Point4 you should define method MoveBy starting with "new" keyword.
Have you tried this?

Greetz
Piotr Olech
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: thechaosengine | last post by:
Hi all, Is there a way to hide a member in a subclass that has been inherited from a base class? Lets leave aside any issues regarding whether its a good idea for a moment. Here's an example...
8
by: Jeroen Smits | last post by:
To Microsoft or other people who are interested, I have a feature request: I would really like to have an option to 'hide' a property or method from an inherited class. For example when I create...
10
by: Jacob | last post by:
Is there a way to make a property of an inherited class invisible to the programmer? I know that using the keyword "new" allows you to create another property in the place of the existing one, but...
6
by: Microsoft | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
4
by: Dan | last post by:
I have a need to make a set of classes that all share the same public methods, some implementation and some data. So, I made an abstract base (BaseClass) with an interface (IBaseClass) and a...
7
by: Dennis | last post by:
I have a class named myclass that inheirits from "baseclass". There is a property of "baseclass" that I don't want exposed in the IDE. The MSDN documentation says" "A derived type can hide an...
2
by: Steven Nagy | last post by:
Hi all, How would I go about hiding an inherited property? In particular, I want to hide the 'BackColor' property of the UserControl class. I will then implement my own back color related...
5
by: PIEBALD | last post by:
I was trying to break some polymorphism, expecting it not to work, but I'm a curious sort. I was seeing what happens when a derived class tries to hide an inherited method with a private new...
14
by: Dom | last post by:
Hi all I'm developing a control, and I need to hide some properties to the user. For example, suppose I need Text property to be completely inacessible (from a Form/Code that is into another...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.