473,320 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 3201
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 "implemented"
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*******@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.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*******@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.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
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...
9
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
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...
3
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....
6
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
20
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...
2
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 ","...
0
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...
15
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....
8
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.