Purpose of interface

Posted by Ray.chayan under C# on 6/22/2010 | Views : 4830 | Status : [Member] | Replies : 7
What is the purpose of interface..we may say here interface implement abstraction here?
Or it force the developer to implement methods & properties that are essential? Or anything else??




Responses

Posted by: Vuyiswamb on: 6/22/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
The Difference between C#,VB.nET,Java and C++ is that C++ can do multiple inheritance , but java and the .net languages i mentioned here cant do do that. Instead, you need to implement the interfaces.


Thank you for posting at Dotnetfunda
[Administrator]

Ray.chayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ray.chayan on: 6/22/2010 [Member] Starter

Up
0
Down
Yes . But in interface there is only the signature of the method . So why should we implement it?

Ray.chayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 6/22/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Well for small applications there is not need to use them , for more info on your question look at this. Remember the same interfaces in java still applies to .net languages.

Why use interfaces ?

http://www.codestyle.org/java/faq-Interface.shtml#interfacedesign

Thank you for posting at Dotnetfunda
[Administrator]

Ray.chayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ray.chayan on: 6/22/2010 [Member] Starter

Up
0
Down
Thanks Vuyiswamb, But I am facing some problem to understand the point in the line given bellow.
"To start with, you may only have one implementation of a given interface, but if you find you need slightly different behaviour in special circumstances, you only need write a class that conforms to one of the existing interfaces and it will drop in place without major modifications."
Could you please explain it .........

Ray.chayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Syedshakeer on: 6/22/2010 [Member] Starter

Up
0
Down
Hi,
Check the following Link
http://ondotnet.com/pub/a/dotnet/2003/06/30/interfaces.html

Syed Shakeer Hussain

Ray.chayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Deeraj on: 6/23/2010 [Member] Starter

Up
0
Down

Interface defines the contract. If you wish to use it, follow its rules.
There is much debate going on between choosing Interfaces to Abstract classes. where abstract classes are much more flexi than interfaces.

BottomLine, If the requirement never changes in terms of the system design go with Interfaces. If you feel the requirment may change in the future better go with abstract classes.

That was just a very higher level explanation.

Hope that helps!

Ray.chayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Proximityinfotech6 on: 6/26/2010 [Member] Starter

Up
0
Down
Interfaces are used to pass objects that are completely different but who all have some methods that are defined in the interface.

Consider a class Rock and a class House. Completely different, and nothing in common, almost. For instance, they both can drop down and crash, say in case of an earthquake :P. Now, you have a class Earthquake with a SmashObjects method. Instead of having to create a parent class for everything on earth that can drop, and have every class, like Rock and House inherit that class, you can make an interface IDroppable and have Rock and House implement that interface. In the interface you define Drop(); and now SmashObject can smash every object that implements IDroppable because it knows, no matter how different, they all have a Drop method.

interface IDroppable
{
Drop();
}

class House : IDroppable
{
Drop()
{
// do house dropping stuff
}
}
____________________________________________________

[url=http://www.visage-glasgow.co.uk/glasgow-tooth-whitening-scotland.html] Teeth Bleaching Glasgow[/url]|
[url=http://www.visage-glasgow.co.uk/glasgow-clear-braces-scotland.html] Invisalign Glasgow[/url]





proximity infotech 6

Ray.chayan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response