473,657 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Partial implementation of interface

Hello friends,
I am new to C#. I have some fundamental doubt. Please, try to answer
it.

1) Ltes say, IFace is an interface which has proto of two methods.
class A implements IFase.

interface IFace
{
void func1(...) {.....}
void func2(...) {.....}
}

class A : IFace
{
void func1(...) {.....}
void func2(...) {.....}
}

class B : A, IFace
{
....
}

Now the question is, in the defination of class B is it neccesory to
implement all two members of IFace. I dont want to change defination
of func1( ) which is from A to B. Or implementation of only one will
solve the problem ?

Sep 21 '07 #1
3 1913
Advait,

Class B, if it does not define anything else, will implement the
interface IFace (you shouldn't need it in the declaration of B, as a matter
of fact).

If you want to provide an implementation of one of the methods defined
in IFace, then you will need to declare the methods in A as virtual, so that
B can override them.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Advait Mohan Raut" <ad***********@ gmail.comwrote in message
news:11******** **************@ t8g2000prg.goog legroups.com...
Hello friends,
I am new to C#. I have some fundamental doubt. Please, try to answer
it.

1) Ltes say, IFace is an interface which has proto of two methods.
class A implements IFase.

interface IFace
{
void func1(...) {.....}
void func2(...) {.....}
}

class A : IFace
{
void func1(...) {.....}
void func2(...) {.....}
}

class B : A, IFace
{
...
}

Now the question is, in the defination of class B is it neccesory to
implement all two members of IFace. I dont want to change defination
of func1( ) which is from A to B. Or implementation of only one will
solve the problem ?

Sep 21 '07 #2
On Sep 21, 8:24 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
Advait,

Class B, if it does not define anything else, will implement the
interface IFace (you shouldn't need it in the declaration of B, as a matter
of fact).

If you want to provide an implementation of one of the methods defined
in IFace, then you will need to declare the methods in A as virtual, so that
B can override them.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard .caspershouse.c om
But is it possible that, a method delared in an interface to be
implemented as virtual ?

Sep 21 '07 #3
Advait Mohan Raut <ad***********@ gmail.comwrote:
Than you, Nicholas Paldino for the nice information. Actuly I came to
conclusion the one cannot override selected methods of the interface,
because in the offline help of VS 2005 (i.e. C# Reference) they have
stated that 'override' will work only if the base class proto is
either 'override' or 'abstract' or 'virtual' .
But when you implement it in the base class you can make it virtual or
abstract. If you do that, you can override it in the derived class.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 21 '07 #4

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

Similar topics

17
6849
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section 18.3.1, 'Iseq'). I want the version for containers that he gives, but also to provide a specialization for construction from a pair<It,It> (eg because that is returned by equal_range()).
9
4636
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
4
1391
by: Andy Venikov | last post by:
Hi all, is there a way to make certain functions of a class be accessible only by specific class? Like "friend class whatever", but only for a few functions? This could be usefull in a following relationship: Client
9
2518
by: Gomaw Beoyr | last post by:
Two question about the "partial classes" (in the next wersion of ..NET). Question 1 ========== Will partial classes (in the next version of C#) have to be declared "partial" in ALL places. I.e. do we have to need to write:
2
1262
by: Billy | last post by:
In .Net 2, when I have created a strongly typed dataset of a SQL table and then 'viewed' the code from the RHM menu. I am taken to the new partial class; as expected, but why do I have a partial class within a partial? plus if I was to inherit an interface then what partial class should I place the interface on, the outer partial class or the inner partial class? Regards Billy
2
2006
by: PeterKellner | last post by:
I'm trying to understand how asp.net 2.0 ties together the codebehind. I've made a simple page, turned debug on so the *0.cs,*1.cs,*2.cs files don't get erased. My first point of confusion is that the *1.cs file is declared like this: public partial class _Default : System.Web.UI.Page {...
2
5559
by: Joseph Geretz | last post by:
When I create a Form, the VB IDE creates the following files in the following hierarchy: Form1.cs Form1.Designer.cs Form1.resx Both Form1.cs and Form1.Designer.cs are partial implementations of a single physical class definition. The VB IDE properly recognizes Form1.cs as a Form (i.e. double-clicking opens the Form designer). It also recognizes
6
1454
by: satyanarayan sahoo | last post by:
What’s the role of Partial keyword which is bydefault written for a class in 2.0 ? public partial class Form1 : Form
10
1520
by: JDeats | last post by:
So I have a class that spans over two partial classes in code, here's an example (do not read much into this, the code is of no practical use, this is just a simple example of where my confusion occurs). // Inside SharedClassExample1.cs public partial class SharedClassExample { public List<stringBooksOnShelf { get; set; } public List<stringBooksOnDesk { get; set; }
0
8392
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
8305
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
8503
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
8605
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
6163
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
4151
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
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
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.