Easy answer... With interfaces you can create a code using class functionality before class is really made...
Good example. You are working in a team on some client/server application.
Your goal is to create a communication between opened sockets using a new
Connection class. But... this class is not coded yet.
For this class, interface IConnection was created which basically tells you
what public methods and properties are inside.
This way you can have methods, which calls and uses functionality of class
that is still in development.
Example of usage:
interface IConnection
{
public void SendData(string data);
public bool Result
{
get;
}
}
class MyClass
{
public MyClass(IConnection myConnection)
{
this.myConnection = myConnection;
}
public bool SendData(string data)
{
this.myConnection.Send(data);
return this.myConnection.Result;
}
IConnection myConnection;
}
Using interfaces means you can implement classes that don't even exist,
because you know, how the logic will work.
You don't need to wait and no one needs to wait for your work after some
Connection class is really created.
2010/3/8 crazy <[email protected]>
> sensible points and thanks ...
> all the things u have described about interface is having Abstract class
> right?
> then why we ned interface? we can use abstract class always [?]
>
> On Mon, Mar 8, 2010 at 10:01 AM, Raghupathi Kamuni
> <[email protected]>wrote:
>
>> Interfaces are used to define the peripheral abilities of a class.
>> An abstract class defines the core identity of a class and there it is
>> used for objects of the same type.
>>
>> An interface cannot have access modifiers for the functions and properties
>> everything is assumed as public.
>> An abstract class can contain access modifiers for the functions and
>> properties.
>>
>> An interface cannot provide any code, just the signature.
>> An abstract class can provide complete, default code and/or just the
>> details that have to be overridden.
>>
>>
>> On Mon, Mar 8, 2010 at 12:34 AM, crazy <[email protected]> wrote:
>>
>>> Hi,
>>> I gone through a lots of articles regarding Abstarct class and
>>> Interfaces..
>>> What is the extra thing in interface but not in Abstract? Not in the C#
>>> conepts whole in OOPS.
>>> why we cant use abstarct classes instead of Interfaces ?
>>> in C# , if we need to implement multiple inheritance,we can use it
>>> anything extra??
>>>
>>> thanks
>>> --
>>> "People who never make mistakes, never do anything."
>>>
>>> dEv
>>>
>>
>>
>
>
> --
> "People who never make mistakes, never do anything."
>
> dEv
>
<<332.gif>>
