473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

What is the equivalent of Delphi's "reintroduce"?

I would like to override a method from an inherited class, but the new
method has a different signature to the inherited class. Example:

class A {
private void Init() {
// code
}
}

class B : A {
private void Init(string text) {
base.Init();
// do something with "text"
}
}

I don't want to see class A's version of Init(). Any instance of class B
should only see Init(text). I know this is possible in Delphi using the
reintroduce modifier, but I couldn't find a way in C#. The "override" and
"new" modifiers didn't help either.
--
Regards,
Charcoal

Nov 16 '05 #1
9 6076
it didn't help because the method Init was not inherited, it should be
declared as protected.

"Chazza" <em***@address.com> wrote in message
news:eP**************@TK2MSFTNGP09.phx.gbl...
I would like to override a method from an inherited class, but the new
method has a different signature to the inherited class. Example:

class A {
private void Init() {
// code
}
}

class B : A {
private void Init(string text) {
base.Init();
// do something with "text"
}
}

I don't want to see class A's version of Init(). Any instance of class B
should only see Init(text). I know this is possible in Delphi using the
reintroduce modifier, but I couldn't find a way in C#. The "override" and
"new" modifiers didn't help either.
--
Regards,
Charcoal

Nov 16 '05 #2
That was a typo in my example. I noticed that but thought that you could
just ignore that.
Nov 16 '05 #3
Try,

class A
{
protected virtual void Init()
{
// code
}
}

class B : A
{
protected override void Init()
{
base.Init();
// do something with "text"
}
}

Regards,
Phil.

"Chazza" wrote:
That was a typo in my example. I noticed that but thought that you could
just ignore that.

Nov 16 '05 #4
Phil,

You missed the point of my post. I already know how to use override the way
it is meant to use. What I'm looking for is a way to override an inherited
method with a new method which has a different signature. Look at my example
of class B again, and you will notice the Init method has one parameter
which is a string. Now look at your example, where has this parameter gone?

I don't know if this is even possible, you might tell me that C# cannot do
this. However, I know in Delphi it was easy to do using the "reintroduce"
modifier and it was very useful in some places...

Regards,
chazza
Nov 16 '05 #5
Chazza <em***@address.com> wrote:
You missed the point of my post. I already know how to use override the way
it is meant to use. What I'm looking for is a way to override an inherited
method with a new method which has a different signature. Look at my example
of class B again, and you will notice the Init method has one parameter
which is a string. Now look at your example, where has this parameter gone?

I don't know if this is even possible, you might tell me that C# cannot do
this. However, I know in Delphi it was easy to do using the "reintroduce"
modifier and it was very useful in some places...


Well, what value would you expect your parameter to have?

You basically can't do this in C#, but I suspect you can fake the same
behaviour using two methods - one which does the overriding, and then
calls the other.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Jon,

I know about the two methods trick, but I wanted to hide the old inherited
method. More specifically I wanted to generate compiler errors where it was
used so I could fix up the code to use the new method, and to prevent people
in future from using the old method directly.
Well, what value would you expect your parameter to have?


Does it matter? It's simply a different signature which I am asking about.
Any Delphi programmer should understand in a heart beat what I am asking
for...but you C# guys, I don't think you understand the concept I'm trying
to explain.

--
Regards,
Charcoal
Nov 16 '05 #7
Chazza <em***@address.com> wrote:
I know about the two methods trick, but I wanted to hide the old inherited
method. More specifically I wanted to generate compiler errors where it was
used so I could fix up the code to use the new method, and to prevent people
in future from using the old method directly.
You definitely can't do that, thank goodness - it would violate
Liskov's Substitutability Principle, for one thing.
Well, what value would you expect your parameter to have?


Does it matter?


Absolutely! If you don't mind it being null or some fixed value, that's
one thing. If Delphi somehow gets a value in some "special" way, that
may be a lot harder to "fake".
It's simply a different signature which I am asking about.
Any Delphi programmer should understand in a heart beat what I am asking
for...but you C# guys, I don't think you understand the concept I'm trying
to explain.


That shouldn't really be a surprise - asking about a Delphi concept in
a C# group is bound to involve a bit more communication than asking
about a Delphi concept in a Delphi group!

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
Chazza,
I believe you want the VB.NET Shadows keyword, which is very similar to the
C# new keyword, but not different then the C# new keyword.

Shadows hides all the base methods and only shows the derived method that
have the same name.

However as Jon states, Shadows also violate the Liskov's Substitutability
Principle.

Hope this helps
Jay

"Chazza" <em***@address.com> wrote in message
news:OR**************@TK2MSFTNGP12.phx.gbl...
Jon,

I know about the two methods trick, but I wanted to hide the old inherited
method. More specifically I wanted to generate compiler errors where it
was used so I could fix up the code to use the new method, and to prevent
people in future from using the old method directly.
Well, what value would you expect your parameter to have?


Does it matter? It's simply a different signature which I am asking about.
Any Delphi programmer should understand in a heart beat what I am asking
for...but you C# guys, I don't think you understand the concept I'm trying
to explain.

--
Regards,
Charcoal

Nov 16 '05 #9
Doh!
C# new keyword, but not different then the C# new keyword. Didn't mean the negative.

It should be "but different then the C# new keyword."

Jay

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:el**************@TK2MSFTNGP15.phx.gbl... Chazza,
I believe you want the VB.NET Shadows keyword, which is very similar to
the C# new keyword, but not different then the C# new keyword.

Shadows hides all the base methods and only shows the derived method that
have the same name.

However as Jon states, Shadows also violate the Liskov's Substitutability
Principle.

Hope this helps
Jay

"Chazza" <em***@address.com> wrote in message
news:OR**************@TK2MSFTNGP12.phx.gbl...
Jon,

I know about the two methods trick, but I wanted to hide the old
inherited method. More specifically I wanted to generate compiler errors
where it was used so I could fix up the code to use the new method, and
to prevent people in future from using the old method directly.
Well, what value would you expect your parameter to have?


Does it matter? It's simply a different signature which I am asking
about. Any Delphi programmer should understand in a heart beat what I am
asking for...but you C# guys, I don't think you understand the concept
I'm trying to explain.

--
Regards,
Charcoal


Nov 16 '05 #10

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

Similar topics

10
by: Dieter Salath? | last post by:
Hi, in our webpage, a user could open a windows explorer to his temp directory with a simple link and usage of the file protocol: <a href="file://C:\temp" target="_blank">C:\temp</a> This...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
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...
0
agi2029
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,...

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.