473,624 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Interface

hi
My question might be a simple questions. I am doing C# maintanance project
I have seen so many places Interface is used in my main class. But I could't not understan
what is the use of Interface. Because Interface having only the Property and method
declaration only. Why we have to use that instead of writing directly in the main class?

1. What is the advatage of use of Interface (or disadvantage) instead of writing property and
method directly

2. When we have to use Abstract class and when we have to use Interface

Is there is any site which is explaining about the difference and usage?? Please let me kno

thank
Kanna
Nov 16 '05 #1
3 3266
You'd write an interface when you want to use the interface as a data type -
and have many classes that you could use.. for example (interfaces always
have an "I" in the front):

IDataAccess objMyObject;

objMyObject = new OfflineAccess() ;
objMyObject = new DirectAccess();
objMyObject = new WebSvcAccess();

Assuming that OfflineAccess, DirectAccess and WebSvcAccess all "implemente d"
that IDataAccess interface - you could instantiate that object with any of
them..
And you use an interface when you want to define JUST the interface (what
methods and properties a class should have) - and you implement an abstract
class when yuo want to do that, and include some base logic or default
functionality of those methods or properties.

HTH
"Kannan" <an*******@disc ussions.microso ft.com> wrote in message
news:FF******** *************** ***********@mic rosoft.com...
hi,
My question might be a simple questions. I am doing C# maintanance project. I have seen so many places Interface is used in my main class. But I could't not understand what is the use of Interface. Because Interface having only the Property and method declaration only. Why we have to use that instead of writing directly in the main class??
1. What is the advatage of use of Interface (or disadvantage) instead of writing property and method directly?

2. When we have to use Abstract class and when we have to use Interface?

Is there is any site which is explaining about the difference and usage?? Please let me know
thanks
Kannan

Nov 16 '05 #2
Client code can refer to objects which implement an interface through an
interface variable. Eg, if two classes implement IPersist, some client code
can use instances of both classes through an IPersist-typed variable.

An abstract class can be partially implemented, ie, it can have both
abstract members AND implemented members. An interface is functionally akin
to an abstract base class with ONLY abstract members.

Brad Williams
"Kannan" <an*******@disc ussions.microso ft.com> wrote in message
news:FF******** *************** ***********@mic rosoft.com...
hi,
My question might be a simple questions. I am doing C# maintanance project. I have seen so many places Interface is used in my main class. But I could't not understand what is the use of Interface. Because Interface having only the Property and method declaration only. Why we have to use that instead of writing directly in the main class??
1. What is the advatage of use of Interface (or disadvantage) instead of writing property and method directly?

2. When we have to use Abstract class and when we have to use Interface?

Is there is any site which is explaining about the difference and usage?? Please let me know
thanks
Kannan

Nov 16 '05 #3
You will need to read a little about Object oriented programming...
Essential what does it mean when we say Interface means we are
specifying a "contract" is the following...

Going back to OOPS 101

Consider Animal as an Interface (read as Animal exhitbits certain
behavior i.e breathing)
Now Man is characterized by this animal behaviour of breathing ( read as
implements interface) Take a different Animal, Fish, it implements the
same behaviour but differently!

So what has the Interface achieved, extracting some common behaviour
"contract" from the different animals

Now if you think certain behaviour can be similarly exhibited you'd use
the abstract class. For example you could say Apes are an classification
(read as abstract) of Animals which breath with lungs. So if you're
dealing with different apes then you would use the behaviour described
by Apes.

Hope that clarifies things


So

Kannan wrote:
hi,
My question might be a simple questions. I am doing C# maintanance project.
I have seen so many places Interface is used in my main class. But I could't not understand
what is the use of Interface. Because Interface having only the Property and method
declaration only. Why we have to use that instead of writing directly in the main class??

1. What is the advatage of use of Interface (or disadvantage) instead of writing property and
method directly?

2. When we have to use Abstract class and when we have to use Interface?

Is there is any site which is explaining about the difference and usage?? Please let me know

thanks
Kannan


--
Regards,
Dilip Krishnan
MCAD, MCSD.net
dilipdotnet at apdiya dot com
Nov 16 '05 #4

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

Similar topics

4
8188
by: Roy Pereira | last post by:
I have an application that is composed of a set of "Content" dlls and a viewer application. The viewer calls a standard set of functions that are present in all the dlls. I maintain this by making my contnent dlls implement an interface created in vb6. The viewer application is bound to this interface. This way, I am able to add Content without redeploying the dlls (I just have to add the new dlls). I want to write new content for...
9
4635
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
2574
by: Doug | last post by:
I am working on an existing .NET (C Sharp) component that had a com interface that was used by a VB component. When it was originally written, it had the SSEAssemblyCom class below - minus the two last methods (for space I modified method names in my example below). I added those. Everything but the two new methods I added referenced the ISSEAssemblyCom interface below. I was told I would need to create a secondary interface...
3
4130
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability. The User Experience, or how the user experiences the end product, is the key to acceptance. And that is where User Interface Design enters the design process. While product engineers focus on the technology, usability specialists focus on the user...
6
3008
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
20
4248
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the interface and accessing the datastore MUST pass in a UserToken in the constructor of the object. Is this not possible? Am I forced to add the UserToken as a property on the object instead? /Ole
2
4984
by: Alex Sedow | last post by:
Why interface-event-declaration does not support multiple declarators like event-declaration? Grammar from C# spec: variable-declarators: variable-declarator variable-declarators "," variable-declarator variable-declarator:
0
2502
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that don't work nearly as well as they should, even for analysts and power users. The reason they haven't reached the masses is because most of the tools are so difficult to use and reveal so little
15
2782
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs. For example: f(3) f(3, )
8
2074
by: rn5a | last post by:
Suppose I have the following class code: Imports System Imports System.Data Imports System.Data.SqlClient Public Class DBSettings Private sqlCmd As SqlCommand Private sqlConn As SqlConnection Public ConnectionString As String
0
8238
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8174
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
8336
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
8478
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...
0
5565
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
4082
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
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1485
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.