468,738 Members | 2,463 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,738 developers. It's quick & easy.

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 6379
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Dinesh Garg | last post: by
8 posts views Thread by Mike C# | last post: by
11 posts views Thread by =?ISO-8859-1?Q?=22Andr=E9s_G=2E_Aragoneses_=5B_kno | last post: by
reply views Thread by zhoujie | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.