You are on page 1of 12

Interface

It is a special type of class Interfaces describe a group of related functionalities that can belong to any class or struct.

Interfaces consist of methods, properties, events, indexers, or any combination of those four member types. An interface cannot contain constants, fields, operators, instance constructors, destructors, or types. It cannot contain static members. Interfaces members are automatically public, and they cannot include any access modifiers.

Why and when to use interface?


External party can understand the functionality of the program easily . For the proper execution of program When a class or struct implements an interface, the class or struct provides an implementation for all of the members defined by the interface.

If it is required to implement the same function by all the classes ,then interface must be declared at the beginning. If the function is declared in the interface then all the classes must implement that same function.

If we change any function in the interface then we automatically get the errors for the classes belonging to it With the help of this it is very easy to locate all the classes which are required to modify. Maintenance becomes easy.

Inheritance
In object-oriented programming, inheritance is the concept that when a class of objects is defined, any subclass that is defined can inherit the definitions of one or more general classes.

Types
A
C

Single inheritance

Multiple inheritance

Multilevel inheritance

Hierarchical inheritance

Why ?
It is always nice if we could reuse something that already exists rather than trying to create the same allover again. It would not only save time and money but also reduce frustration and increase reliability. It can save the efforts of developing and testing the same again.

When?
There are several other reasons why you might want to use interfaces instead of class inheritance: Interfaces are better suited to situations in which your applications require many possibly unrelated object types to provide certain functionality. Interfaces are more flexible than base classes because you can define a single implementation that can implement multiple interfaces. Interfaces are better in situations in which you do not need to inherit implementation from a base class. Interfaces are useful in cases where you cannot use class inheritance. For example, structures cannot inherit from classes, but they can implement interfaces.

courtesy
www.Msdn.com www.Google.com www.Wikipedia.com Oop with c++ by Balagurusamy

Thank you

You might also like