Re: base, derived objects

Chris Anderson <[email protected]> Thu, 3 May 2007 17:13:43 +0100
Newsgroups gmane.comp.windows.devel.dotnet.cx
Message-ID <[email protected]>
No, and it makes sense why not.
 
The derived class may have completely different construction requirements.
It may (as in my sample case) expand upon the parameters required, it may reduce the parameters, supplying calculated or default values for the others, or it may need completely different parameters and use them to calculate the base ctor params.
 
You could code the ctor to take a object of type Base, but how would you extract the private members from it without exposing them to other classes. (You could mark them as internal which would help a little, but that may still be against the design, or you could use Reflection which would be slow, require elevated rights, and would prove brittle over time)
 
Personally in your shoes I would look at writting a macro/addin to emit the standard method of using ":base(...)" and just fill the params.
For a really basic version, you could get it to simply copy the derived ctor params leaving he user to modify the list based on what the base really wanted
That would cover most cases (where the number, type and ordering of the params was the same)
 
 

________________________________

From: Discussion relating to the specifics of the C# and Managed C++ languages on behalf of Peter Osucha
Sent: Thu 03/05/2007 16:46
To: [email protected]
Subject: Re: [DOTNET-CX] base, derived objects



Chris,

That's what I'm doing now.  I was wondering if there was some sort of
shorthand (shorterhand?) that would allow me to just set the base
object.  It's easy enough to just create another constructor that takes
a 'Base' as its argument...

Peter

-----Original Message-----
From: Discussion relating to the specifics of the C# and Managed C++
languages [mailto:[email protected]] On Behalf Of Chris
Anderson
Sent: Thursday, May 03, 2007 11:28 AM
To: [email protected]
Subject: Re: [DOTNET-CX] base, derived objects

public Derived (<derived param list>) : base(pass appropriate params to
base) {}

eg

public Base (int param1, string param2) {...}

public Derived (int p1, string p2, int p3) : base(p1,p2)
{
   // do something additional with p3
}



===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com