This is a discussion on c# interface within the C# Programming forums, part of the Software Development category; Can anybody explain me about the concept of Interface and its advantages in C#.net?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| hi, Interface is used to rectify the drawback of multiple inheritance, the creators of C# have introduced a new concept called interfaces. Java programmers may be well aware of this concept. All interfaces should be declared with the keyword interface. You can implement any number of interfaces in a single derived class, but you should provide signatures to all method definitions of the corresponding interfaces. Advantages: 1.This construct makes the software flexible for future changes. 2.The client using your class through a method argument or instance variable will not have to know anything about the class 3.The chance of failures, faults or errors getting thrown when you make changes to existing code will be lower when the classes are decoupled. Regards Manivannan.s |
| |||
| hi Interfaces in C# are provided as a replacement of multiple inheritance. Because C# does not support multiple inheritance, it was necessary to incorporate some other method so that the class can inherit the behavior of more than one class, avoiding the problem of name ambiguity that is found in C++. With name ambiguity, the object of a class does not know which method to call if the two base classes of that class object contain the same named method. The classes in C# can now make use of the keyword "interface" to inherit more than one behavior from different interfaces. When a class inherits from one or more interfaces, we say that the class is implementing that interface(s). The most important thing to remember about interfaces is that the classes can only implement the methods defined in the interface because in C#, an interface is a built-in keyword that declares a reference type that includes method declarations. In addition to methods, interfaces can define properties, indexers, and events uses: 1. To allow a class to inherit multiple behaviors from multiple interfaces. 2. To avoid name ambiguity between the methods of the different classes as was in the use of multiple inheritance in C++. 3. To combine two or more interfaces such that a class need only implement the combined result. 4. To allow Name hiding. Name hiding is the ability to hide an inherited member name from any code outside the derived class. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What is the use of interface? | Mramesh | C# Programming | 5 | 02-08-2008 04:51 AM |
| What is the Servlet Interface? | Arun | Java Programming | 2 | 09-10-2007 04:35 AM |
| What is the Set interface? | anbuchezhians | Java Programming | 4 | 09-10-2007 04:18 AM |
| Map interface in Collection Api | leoraja8 | Java Programming | 6 | 09-06-2007 03:51 AM |
| Do we have interface to schedule a task like ITaskscheduler interface for desktop.... | theone | Mobile Software Development | 1 | 07-24-2007 11:29 PM |