473,803 Members | 3,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Base keyword - HELP

Hi,
Am having a base class that implements an interface (air code) :

class BaseClass : SomeInterface
{
void SomeInterface.I mplMethod()
{
// -- code here --
}
}

class Derived : SomeInterface
{
void SomeInterface.I mplMethod()
{
//NEED TO CALL BASE'S IMPLEMENTATION HERE
// -- code here --
}
}

Without making the implementations public, is there a way to do it?

TIA
Krishnan
Nov 17 '05 #1
17 2061
> class BaseClass : SomeInterface
class Derived : SomeInterface


The derived class doesn't inherit from the base class?

However, even when inheriting, I couldn't find a way to call the base
class interface function. Maybe someone else knows how to do it?

I only found this work-around, by moving the code to a helper function.
Like this:

interface SomeInterface
{
void ImplMethod();
}

class BaseClass : SomeInterface
{
protected void Method() { /* Code goes here */ }
void SomeInterface.I mplMethod() { Method() }
}

class Derived : BaseClass, SomeInterface
{
void SomeInterface.I mplMethod() { base.Method(); }
}

Greetings,
Wessel
Nov 17 '05 #2
>Without making the implementations public, is there a way to do it?

Your naming is a bit confusing since Derived doen't derive from
BaseClass. But you can do

SomeInterface si = new BaseClass();
si.ImplMethod() ;

if that's what you want.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #3
You could make the method internal if both classes are in the same assembly
or you really derive from that class and make the method protected.

"Krishnan" <kr************ *********@myrea lbox.com> schrieb im Newsbeitrag
news:eO******** ******@tk2msftn gp13.phx.gbl...
Hi,
Am having a base class that implements an interface (air code) :

class BaseClass : SomeInterface
{
void SomeInterface.I mplMethod()
{
// -- code here --
}
}

class Derived : SomeInterface
{
void SomeInterface.I mplMethod()
{
//NEED TO CALL BASE'S IMPLEMENTATION HERE
// -- code here --
}
}

Without making the implementations public, is there a way to do it?

TIA
Krishnan

Nov 17 '05 #4
Thanks for the reply. I missed out on mentioning the base class inheritance
in the derived class.
"Wessel Troost" <no****@like.th e.sun> wrote in message
news:op.styc180 rxgtv7i@asbel.. .
class BaseClass : SomeInterface
class Derived : SomeInterface


The derived class doesn't inherit from the base class?

However, even when inheriting, I couldn't find a way to call the base
class interface function. Maybe someone else knows how to do it?

I only found this work-around, by moving the code to a helper function.
Like this:

interface SomeInterface
{
void ImplMethod();
}

class BaseClass : SomeInterface
{
protected void Method() { /* Code goes here */ }
void SomeInterface.I mplMethod() { Method() }
}

class Derived : BaseClass, SomeInterface
{
void SomeInterface.I mplMethod() { base.Method(); }
}

Greetings,
Wessel

Nov 17 '05 #5
Just one Q. The line,
void SomeInterface.I mplMethod() { Method() }

would call the most derived version's method, right? I mean there is no
"MyClass" keyword in C# :(

TIA
Krishnan
Krishnan "Pay your tax with a smile", says the government. I tried. They
wanted cash.
"Wessel Troost" <no****@like.th e.sun> wrote in message
news:op.styc180 rxgtv7i@asbel.. .
class BaseClass : SomeInterface
class Derived : SomeInterface


The derived class doesn't inherit from the base class?

However, even when inheriting, I couldn't find a way to call the base
class interface function. Maybe someone else knows how to do it?

I only found this work-around, by moving the code to a helper function.
Like this:

interface SomeInterface
{
void ImplMethod();
}

class BaseClass : SomeInterface
{
protected void Method() { /* Code goes here */ }
void SomeInterface.I mplMethod() { Method() }
}

class Derived : BaseClass, SomeInterface
{
void SomeInterface.I mplMethod() { base.Method(); }
}

Greetings,
Wessel

Nov 17 '05 #6
> class Derived : SomeInterface
{
void SomeInterface.I mplMethod()
{
//NEED TO CALL BASE'S IMPLEMENTATION HERE
base.ImplMethod ();
// -- code here --
}
}

Nov 17 '05 #7
> Just one Q. The line,
void SomeInterface.I mplMethod() { Method() }

would call the most derived version's method, right? I mean there is no
"MyClass" keyword in C# :(

C# does have a "MyClass" keyword: this. You could write:

void SomeInterface.I mplMethod() { this.Method() }

Greetings,
Wessel
Nov 17 '05 #8
> base.ImplMethod ();

That doesn't work. Try it.

Greetings,
Wessel
Nov 17 '05 #9

"Krishnan" <kr************ *********@myrea lbox.com> schrieb im Newsbeitrag
news:eM******** ******@tk2msftn gp13.phx.gbl...
Just one Q. The line,
void SomeInterface.I mplMethod() { Method() }

would call the most derived version's method, right? I mean there is no
"MyClass" keyword in C# :(

Why this would be a problem?
In the code of Wessel Troost BaseClass.Metho d is not virtual, so there never
will be a more derived version.

Christof
Nov 17 '05 #10

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

Similar topics

10
2282
by: Jacek Generowicz | last post by:
Where can I find concise, clear documentation describing what one has to do in order to enable Python's internal help to be able to provide descriptions of Python keywords ? I am in a situation where I have to give Python novices the ability to fix this for themselves easily. Failing "concise" and "clear", how about "complete and correct" ?
1
2968
by: Bob Rock | last post by:
Hello, I have read that the base keyword can be used not only to control a base class instantiation (thus calling one of the base class constructors) but also to access any other public or protected method in the parent class ... I have search all over for an example of how to do this but have failed. What I was wondering is about the syntax necessary to make such a call ..... Thx.. Bob Rock
7
1152
by: Rob Meade | last post by:
Hi all, Ok - I'm going around in circles and would appreciate some help. I have written a windows service, which up until I tried to be clever was working well :o) I have a main class which inherits a base class, I also have a "configuration" class which stores a load of values read in from an xml file which I would like to be available at any time (without reading the xml file
5
1118
by: BartlebyScrivener | last post by:
Using ActivePython 2.4.3 on Windows XP While in the Pythonwin IDE, if I seek keyword help by issuing the following command: >>>help ('while') I get: Sorry, topic and keyword documentation is not available because the
11
2711
by: jyck91 | last post by:
// Base Conversion // Aim: This program is to convert an inputted number // from base M into base N. Display the converted // number in base N. #include <stdio.h> #include <stdlib.h> #include <string.h> #define LENGTH 20 int temp, m, n, i, r, base10, true;
0
9703
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
9564
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,...
1
10295
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
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
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.