An interface is a contract and defines the requisite behavior of generalization of types. For example, vehicle behavior includes ignition on, ignition off, turn left, turn right, accelerate, and decelerate. A car, truck, bus, and motorcycle are included in the vehicle category. As such, they must encapsulate baseline behavior representative of all vehicles. The vehicle interface defines that baseline. Specific vehicle types implement that baseline behavior differently than others. A car accelerates differently from a motorcycle. A motorcycle turns differently from a bus. An interface mandates a set of behaviors, but not the implementation. The derived type is free to implement the interface in an appropriate manner. Interfaces must be inherited. You cannot create an instance of an interface.
Any class or structure that inherits an interface commits to implementing the members of that interface. An interface is an array of related functions that must be implemented in a derived type. Members of an interface are implicitly public and abstract.
public interface IZ {
void MethodA (int a);
void MethodB (int a);
void MethodC (int a);
void MethodD (int a);
}
Nice Name "Maysam"
What is an interface in c# programming?
An important concept of interfaces is that they form a contract. Objects that implement an interface must implement all methods defined in the interface. For example, objects that implement ICollection must provide collection manipulation methods. You can use the 'is' operator to check that an object implements an interface, and once you know it does you can expect certain methods to be there (otherwise it wouldn't compile).
Reply:An interface is like a special class that has only function declarations and no implementation defined. Such a class needs to be 'extended' (special type of inheritance) to a new class in which the interface-methods may be defined.
Interface is an OOPs concept and hence applies in similar way to all languages that are Object Oriented, like C#.
Enough confused? read example at - http://www.developer.com/net/csharp/arti...
More explanation and example at - http://www.codeguru.com/csharp/csharp/cs...
.
Reply:Okay, thanks to another individual, who by the way answered this question earlier, I was able to derive a better meaning and explaination. An interface can be thought of as a class with no properties or data, only empty methods. I had wrestled with the reason behind having a empty methods, I mean what's the point right. Well the point is naming. All objects are made of properties, data, and methods. Interfaces allows developers to use the same method names, just providing different functionality.
Reply:i will try to be correct about that, so if someone see a reason to correct me then feel free.
interface is basically a method that has no body.
so why should one use it?
assume that you write a program that simulate dogs. but you are not the one who responsible for writing the code that make the dog to bark. but you need that next programmer who will write the bark method will refer to your code. then you write an empty method that called "MakeBark" and then the next programmer will have to refer into that code and will be able populate the MakeBark with his barking code. that way both of you working with same same, code some how.
but that was in very general, so i would advise you to google for some more info about:
Abstract and Interface.
good luck
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment