473,769 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the equivalent of Delphi's "reintroduc e"?

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 6108
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******** ******@TK2MSFTN GP09.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 "reintroduc e"
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 "reintroduc e"
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.co m>
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 Substitutabilit y 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.co m>
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 Substitutabilit y
Principle.

Hope this helps
Jay

"Chazza" <em***@address. com> wrote in message
news:OR******** ******@TK2MSFTN GP12.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******** ******@TK2MSFTN GP15.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 Substitutabilit y
Principle.

Hope this helps
Jay

"Chazza" <em***@address. com> wrote in message
news:OR******** ******@TK2MSFTN GP12.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
60719
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 worked very well a long time, but now it does not work anymore. We use IE6 and Microsoft Windows XP Professional 2002 SP2. I guess it has something to do with new IE security features. Does
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.