472,958 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Hiding Base Class Properites from derived class instance

Base class:
class AssetBase
{
string _clli;

public string CLLI
{
get
{
return _clli;
}
set
{
_clli = value
}
}
}
In Derived Class I want to give different name to the base class property
and internally refer the base class property like below
class Asset: BaseAsset
{
public string Location
{
get
{
base.CLLI;
}
set
{
base.CLLI = value;
}
}
}

Now , when the developer use this dll in their project and create Asset
instance I want to hide the AssetBase Property CLLI , all i want to see them
is Location. I can do this by making base class properties to protected ,
but I want some of the property to be exposed to the developer
as it's defined in base class. How can I do that ?
Thanks
baski

Nov 16 '05 #1
6 6613
Hi Baski,

You can move Asset and AssetBase into a separate assembly and make CLLI
internal. Remember to make the classes public so calling code can see them.

public class AssetBase
{
string _clli;

internal string CLLI
{
get
{
return _clli;
}
set
{
_clli = value;
}
}
}

public class Asset: AssetBase
{
public string Location
{
get
{
return base.CLLI;
}
set
{
base.CLLI = value;
}
}
}

Joe
--
http://www.csharp-station.com

"Microsoft" <ba***@aldensys.com> wrote in message
news:Os*************@TK2MSFTNGP10.phx.gbl...
Base class:
class AssetBase
{
string _clli;

public string CLLI
{
get
{
return _clli;
}
set
{
_clli = value
}
}
}
In Derived Class I want to give different name to the base class property
and internally refer the base class property like below
class Asset: BaseAsset
{
public string Location
{
get
{
base.CLLI;
}
set
{
base.CLLI = value;
}
}
}

Now , when the developer use this dll in their project and create Asset
instance I want to hide the AssetBase Property CLLI , all i want to see them is Location. I can do this by making base class properties to protected ,
but I want some of the property to be exposed to the developer
as it's defined in base class. How can I do that ?
Thanks
baski

Nov 16 '05 #2
Hi Joe,

It's actually in different dll's. The problem is I don't know which property
in the base class will be renamed in the derived class.

If the base class properties is not renamed in the derived class , I want
the developer to see as it's defined in base class from derived class
instance variable.

Thanks

Baski

"Joe Mayo" <jm***@nospamAtCSharpDashStation.com> wrote in message
news:O0**************@tk2msftngp13.phx.gbl...
Hi Baski,

You can move Asset and AssetBase into a separate assembly and make CLLI
internal. Remember to make the classes public so calling code can see
them.

public class AssetBase
{
string _clli;

internal string CLLI
{
get
{
return _clli;
}
set
{
_clli = value;
}
}
}

public class Asset: AssetBase
{
public string Location
{
get
{
return base.CLLI;
}
set
{
base.CLLI = value;
}
}
}

Joe
--
http://www.csharp-station.com

"Microsoft" <ba***@aldensys.com> wrote in message
news:Os*************@TK2MSFTNGP10.phx.gbl...
Base class:
class AssetBase
{
string _clli;

public string CLLI
{
get
{
return _clli;
}
set
{
_clli = value
}
}
}
In Derived Class I want to give different name to the base class property
and internally refer the base class property like below
class Asset: BaseAsset
{
public string Location
{
get
{
base.CLLI;
}
set
{
base.CLLI = value;
}
}
}

Now , when the developer use this dll in their project and create Asset
instance I want to hide the AssetBase Property CLLI , all i want to see

them
is Location. I can do this by making base class properties to protected ,
but I want some of the property to be exposed to the developer
as it's defined in base class. How can I do that ?
Thanks
baski


Nov 16 '05 #3
"Microsoft" <ba***@aldensys.com> wrote:
In Derived Class I want to give different name to
the base class property


You can't (and shouldn't) do that, because then your derived-class
objects could not be used in situations where the base-class objects
were used; and that's essentially the purpose of inheritance.

Why do you want to do this renaming? Perhaps you could choose a more
generic name in the base class that would be suitable for both.

P.
Nov 16 '05 #4
We have base framework , which will be used for multiple clients , each
client will call the properties in different names. Base class will not be
used by the developer
any where. We are using the inheritance to get most
functionality(reusability) from base class and easily adopt the new client
with simple customization.

thanks
Baski

"Paul E Collins" <fi******************@CL4.org> wrote in message
news:cp**********@hercules.btinternet.com...
"Microsoft" <ba***@aldensys.com> wrote:
In Derived Class I want to give different name to
the base class property


You can't (and shouldn't) do that, because then your derived-class objects
could not be used in situations where the base-class objects were used;
and that's essentially the purpose of inheritance.

Why do you want to do this renaming? Perhaps you could choose a more
generic name in the base class that would be suitable for both.

P.

Nov 16 '05 #5
The C# solution to hiding is that a derived class member will hide a base
class member only if they have the same name and signature. If I understand
you correctly, you want some automatic mechanism to hide a base class
property if a derived class property accesses that base class property,
which isn't an available feature. The solution I provided still doesn't
give access to CLLI from an AssetBase reference outside the assembly, so
that is probably not what you need either.

Joe
--
http://www.csharp-station.com

"Baski" <ba***@aldensys.com> wrote in message
news:er***************@TK2MSFTNGP12.phx.gbl...
Hi Joe,

It's actually in different dll's. The problem is I don't know which property in the base class will be renamed in the derived class.

If the base class properties is not renamed in the derived class , I want
the developer to see as it's defined in base class from derived class
instance variable.

Thanks

Baski

"Joe Mayo" <jm***@nospamAtCSharpDashStation.com> wrote in message
news:O0**************@tk2msftngp13.phx.gbl...
Hi Baski,

You can move Asset and AssetBase into a separate assembly and make CLLI
internal. Remember to make the classes public so calling code can see
them.

public class AssetBase
{
string _clli;

internal string CLLI
{
get
{
return _clli;
}
set
{
_clli = value;
}
}
}

public class Asset: AssetBase
{
public string Location
{
get
{
return base.CLLI;
}
set
{
base.CLLI = value;
}
}
}

Joe
--
http://www.csharp-station.com

"Microsoft" <ba***@aldensys.com> wrote in message
news:Os*************@TK2MSFTNGP10.phx.gbl...
Base class:
class AssetBase
{
string _clli;

public string CLLI
{
get
{
return _clli;
}
set
{
_clli = value
}
}
}
In Derived Class I want to give different name to the base class property and internally refer the base class property like below
class Asset: BaseAsset
{
public string Location
{
get
{
base.CLLI;
}
set
{
base.CLLI = value;
}
}
}

Now , when the developer use this dll in their project and create Asset
instance I want to hide the AssetBase Property CLLI , all i want to see

them
is Location. I can do this by making base class properties to protected , but I want some of the property to be exposed to the developer
as it's defined in base class. How can I do that ?
Thanks
baski



Nov 16 '05 #6
> The C# solution to hiding is that a derived class member will hide a base
class member only if they have the same name and signature.


I think that's a bit misleading - the overload resolution rules will
actually use methods in the derived class in preference to methods in the
base. Even if there is an exact match in the base, a derived version that
requires parameter type conversion will still be used.

Here are two other rules that are relevant here:

A field, property, event, or nested type hides all inherited members with
the same name (including all the overloaded inherited methods).

A method hides all non-method inherited members with the same name.
Nov 16 '05 #7

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

Similar topics

1
by: Dinesh Garg | last post by:
Hi All, Following program does not compile because Class B does not provide " int foo(int) ". My Doubt here is why C++ hides the function in derived class with same name ;infact derived class...
5
by: hillcountry74 | last post by:
Hi, I'm a newbie to OOP and VB.Net. In the business layer, I have a base class, which is an abstract class in VB.Net. The derived class overrides a method and calls other methods in the base...
1
by: question | last post by:
I want to know incase there is any performance difference or overhead in calling a base class method and a derived class method. Basically I am talking about simple method that is not overridden...
8
by: Mike C# | last post by:
Suppose I have a base class "foo". Another class, "bar" derives from it. Base class "foo" has a method called "rob_the_liquor_store()", and the inherited class "bar" overrides this method with one...
11
by: =?ISO-8859-1?Q?=22Andr=E9s_G=2E_Aragoneses_=5B_kno | last post by:
I have a simple class: public class BaseClass { private string propertyA; protected string PropertyA { get { return propertyA; } set { propertyA = value; }
2
by: Ninereeds | last post by:
I'm messing around with using mixin-layers (look for papers by Yannis Smaragdakis and Don Batory) to define data structures. One issue is that nodes tend to have pointers to other nodes - the...
1
by: Rahul | last post by:
Hi Everyone, I have the following code, class AA { public: int i; };
3
by: Edan | last post by:
I have a base class with protected members (`Base`). The function `MakeBase()` is a member function of another class, that returns a `Base` object initialized with private members of this class. Now...
0
by: brboLikus | last post by:
Hello everybody! My problem is somewhat strange since I can't think of any normal situation where one would like to do what I need, but here it goes. I need to somehow cast a base class to a...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.