473,785 Members | 3,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the use of interface

Hai friends,

I really wonder, If the interface does not have any
definition, Y do we need to use interface. You can then only we can use
Multiple inheritance. I really cant understand, Just for declararion y
do we need to use interface. Anyhow the method name and definition ll
be in the derived class. Instead of that we can do all code in the
derived class itself right...? Then y these concept came. If anybody
know, please explain me with an example has right situation...

Thanks in advance

Jun 7 '06 #1
4 20640
"Raja Chandrasekaran" <Ra*****@gmail. com> a écrit dans le message de news:
11************* *********@j55g2 00...legr oups.com...

| I really wonder, If the interface does not have any
| definition, Y do we need to use interface. You can then only we can use
| Multiple inheritance. I really cant understand, Just for declararion y
| do we need to use interface. Anyhow the method name and definition ll
| be in the derived class. Instead of that we can do all code in the
| derived class itself right...? Then y these concept came. If anybody
| know, please explain me with an example has right situation...

The quick answer is that an interface is a contract that can be implemented
in a class.

You mention multiple inheritance; yes, one interface can inherit from more
than one other interface, but classes do not inherit from interfaces, they
implement them.

The difference between an interface and a class is that an interface is
purely a contractual definition that has no implementation at all. It is
similar to a pure abstract class, except that an abstract class can also
contain state fields and base behaviour.

Interfaces are intended to define the what without defining the how.

If you inherit from one class into another, then the derived class "is" also
the base class.

But because you can never derive from more than one base class at a time,
the ability to implement more than one interface gives people the impression
that interfaces provide multiple inheritance.

Another difference between an interface and a base class is that a base
class has to be the root of a hierarchy, vertical inheritance; whereas an
interface can be implemented across multiple hierarchies, a sort of
horizontal "inheritanc e"

A simple example of the differences is :

class Vehicle
{
}

class Car : Vehicle
{
}

interface ISteerable
{
void Steer();
}

class Car : Vehicle, ISteerable
{
void Steer()
{
// change direction of wheels
}
}

abstract class Boat : ISteerable
{
abstract void Steer();
}

class Speedboat : Boat
{
override void Steer()
{
// turn outboard motor
}
}

class Ship : Boat
{
override void Steer()
{
// turn rudder
}
}

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jun 7 '06 #2
See;

http://en.wikipedia.org/wiki/Virtual_inheritance
"Raja Chandrasekaran" wrote:
Hai friends,

I really wonder, If the interface does not have any
definition, Y do we need to use interface. You can then only we can use
Multiple inheritance. I really cant understand, Just for declararion y
do we need to use interface. Anyhow the method name and definition ll
be in the derived class. Instead of that we can do all code in the
derived class itself right...? Then y these concept came. If anybody
know, please explain me with an example has right situation...

Thanks in advance

Jun 7 '06 #3
"Shawnk" <Sh****@discuss ions.microsoft. com> a écrit dans le message de news:
BF************* *************** **...icrosof t.com...

| http://en.wikipedia.org/wiki/Virtual_inheritance

This article doesn't talk about interfaces at all, which is what the OP
asked. Did you get the right link ?

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jun 7 '06 #4
Joanna,

Thanks for pointing this out (always appreciate your comments).
As always pressed for time an I should have put in a few more links.

http://en.wikipedia.org/wiki/Virtual_inheritance
http://en.wikipedia.org/wiki/Multiple_inheritance
http://en.wikipedia.org/wiki/Interface_%28Java%29
http://en.wikipedia.org/wiki/Interfa...ter_science%29

A key concept to understand is Implementation Inheritance (II) vs Virtual
Inheritance (VI).

This separates Multiple Inheritance (which has II and VI functionality) from
Interfaces (which only has VI functionality).

Although the links disgress from C# it helps to understand the Java/C++
architectures to better understand the single inheritance/interface
inheritance architecture of C#.

Understanding the semantics (logical meaning) of 'Type polymorphism',
'Virtual inheritance', 'Implementation Inheritance' and 'Mulitple
Inheritance' also helps to understand the abstract functionality of virtual
inheritance.

I often use WikiPedia as a terminology reference as it has helped me (and
hopefully others) to articulate design/architecture issues (independent of
our personal preferences in design choices).

Thanks, again, for pointing out my rather terse reply :-)

Shawnk



"Joanna Carter [TeamB]" wrote:
"Shawnk" <Sh****@discuss ions.microsoft. com> a écrit dans le message de news:
BF************* *************** **...icrosof t.com...

| http://en.wikipedia.org/wiki/Virtual_inheritance

This article doesn't talk about interfaces at all, which is what the OP
asked. Did you get the right link ?

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer

Jun 9 '06 #5

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

Similar topics

5
1551
by: HAM | last post by:
One of my friends asked if the followings have any meanings? '------------- Public Interface IRenderable Sub Render() MustInherit Class Engine MustOverride Sub TurnOn() Interface IAutomatic Sub Start() End Interface
12
2807
by: Steve W. | last post by:
I just read the section (and did the exercise) in the C# Step by Step book that covers Explict Interface Implementation (where you specify in the method implementation the specific interface that you are implementing in the class. Other than to resolve the problem that arises when a class implements two interfaces with the same method signature, what good is it?
3
15757
by: Amit chaturvedi | last post by:
Dear Friends Please tell me following thing Que -: what is the main use of interface in .net Que -: What is difference between abstract class and interface Que -: How to make class in Object Oriented Form? (in c# Please mail me at my mail id - chaturvediamit2001@yahoo.co.in
21
13847
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered by Sets. - ICollection cannot decide containment - IList promises indexability by the natural numbers, which is not achievable (since i hash elements, not sort them). - IDictionary is definatly not setlike. Although I can, of course, define...
6
6080
by: John Salerno | last post by:
I understand how they work (basically), but I think maybe the examples I'm reading are too elementary to really show their value. Here's one from Programming C#: #region Using directives using System; using System.Collections.Generic; using System.Text;
1
10419
by: Mitan | last post by:
Hello, I'm a beginner with what appears to be a simple question for which I haven't been able to get an answer. Can someone explain what "implementation code" is in relation to VB.NET? I want to be sure I have a good understanding of this before I continue with my studies. Thanks in advance. Semper Fi
19
2898
by: Charles Law | last post by:
Take a solution with a project hierarchy along the lines of an n-tier system, so that we have a data layer, business layer and presentation layer. The presentation layer is coupled to the business layer, and the business layer is coupled to the data layer. So far so good. Suppose the data layer raises an event, and it passes Me (the sender) as an object, and e (MyEventArgs, a descendent of EventArgs) to the layer above (the business...
17
2284
by: Zytan | last post by:
Aren't all classes interfaces? What constitutes an interface (and with it, the "I" prefix distinction)? Zytan
6
1886
by: S_K | last post by:
Hi, I've been toying around with interfaces in C#. They are fun but can anybody give me some examples of where interfaces are used and what they are used for? Thanks so much. Steve
0
9645
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
9480
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
10327
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10092
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
9950
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
7499
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
6740
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
5381
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.