Re: Inheritance design issue

From: Lucas Tam (REMOVEnntp_at_rogers.com)
Date: 11/25/04


Date: Thu, 25 Nov 2004 19:34:59 GMT


"Mark O'Flynn" <mark.oflynn@ozemail.com.au> wrote in
news:DIppd.337$Mp6.8217@nnrp1.ozemail.com.au:

> If Phone is changed in the Person object, this will not be reflected
> in the Manager object.
>
> It seems to me that this would be a common situation faces in OOP, so
> any advice on how I can get an inheritied object to maintain a
> reference to the base object's data, or how best to design a solution
> would be most appriciated.

I think you'll want to declare your manager phone property as "Shadows"
phone. This allows you to create an identically named proprety called
phone which won't override the base class property:

Shadows
Optional. Indicates that this property shadows an identically named
programming element, or set of overloaded elements, in a base class. You
can shadow any kind of declared element with any other kind. If you
shadow a property with another property, the arguments and the return
type do not have to match those in the base class property. A shadowed
element is unavailable from within the derived class that shadows it,
unless the shadowing element is inaccessible, for example if it is
Private.
Note You cannot specify both Overloads and Shadows in the same
property declaration.

To access the bass class data you'll need to provide a property to
access the bass class object (i.e. GetParentObject which will return
Mybase) or provide a property to access the bass class property (i.e.
GetPersonPhone).

MyBase
The MyBase keyword behaves like an object variable referring to the base
class of the current instance of a class. MyBase is commonly used to
access base class members that are overridden or shadowed in a derived
class. In particular, MyBase.New is used to explicitly call a base class
constructor from a derived class constructor.

It is invalid to use MyBase to call MustOverride base methods.

These are just ideas on the top of my head... and are untested. Maybe
someone with more OO experience can provide a better solution.

-- 
Lucas Tam (REMOVEnntp@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/


Relevant Pages

  • RE: Shadowing a base class event handler - bug?
    ... Indicates that this event shadows an identically named ... programming element in a base class. ... A shadowed element is unavailable from within ... Shadowing a base class event handler - bug? ...
    (microsoft.public.dotnet.framework.clr)
  • Re: VB.Net Polymorphic Bug!
    ... The entire point of "Shadows" is that they are not polymorphic! ... MainForm.Widget does not override Form.Widget. ... > Can't override Base class 'X' because of different structure. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: VB.Net Polymorphic Bug!
    ... After my initial annoyance with Shadows I can see a need for Shadows to be ... hole by precluding accessing the base class behaviour in the function ... But this gives the impression that writing to ... > So you Shadow the base class 'X' in the derived class. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Why Overloads needed
    ... Without Overloads, Shadows would be required; and since neither is implied I ... point in the future I modify Base class to overload Item, ... Public Class OverloadedBase ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Polymorphism & Collections
    ... MyBaseCollection (with it possibly being a sub class of a ... MyExtendedBase and MyExtendedBaseCollection are sub classes of MyBase ... When you say a "subclass" it means that it inherits from a base class ...
    (microsoft.public.dotnet.languages.csharp)