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 4 3752
A Ratcliffe <ar********@arc hiNOSPAMmagic.n et> 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 Substitutabilit y Principle (namely that whatever you
can do with a Point3, you should be able to do with a Point4).
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" wrote It sounds like your Point4 shouldn't be derived from a Point3 - it breaks Liskov's Substitutabilit y 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
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********@arc hiNOSPAMmagic.n et> wrote in message
news:OF******** ******@TK2MSFTN GP09.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
Mon, 3 Nov 2003 12:46:13 -0000, on
microsoft.publi c.dotnet.langua ges.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 similar to what I'm thinking about.
Lets suppose I make a class called RoleCollection.
|
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 a subclass and supply a default
value for a property. Currently I create a new property, using the new
keyword, and only supply the get accessor witch will always return the
predefined value. But I would really like to be able to hide it...
|
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 how can I make the
property hidden and not available at all?
Thanks,
Jacob
|
by: Microsoft |
last post by:
Base class:
class AssetBase
{
string _clli;
public string CLLI
{
get
|
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 handful of
inherited classes. The static method calls the ctor of the appropriate
inherited class and returns it as type IBaseClass. There are no new
methods or properties in the inherited classes and public clients never
need to know which...
| |
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 inherited member by defining a new member with
the same signature. This might be done to make a previously public member
private or to define new behavior for an inherited method that is marked as
final. "
However, this does not hide the...
|
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 properties and
collections.
I can do all the latter, but I don't want to build this nice designable
properties and have this big ugly 'BackColor' property available to the
user of my components, which will need to be set to Transparent all the
|
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 method, expecting an error or warning; I got
neither with the result that the inherited method does _not_ get hidden (i.e.
not possibe to break polymorphism/inheritance this way, yay!)
My question then is, why is there no warning that the code may...
|
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 project/assembly).
I tried with attributes:
<Browsable(False), _
EditorBrowsable(EditorBrowsableState.Never), _
RefreshProperties(RefreshProperties.Repaint), _
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |