FAtechs is a Web Site where you can find a lot of things related to tech and Education. Our Posts are mostly about Programming, Information, Technology,Software, Reviews & Everything You need to Know. You can also find Books and Novels here. Your appreciation and criticism will be welcomed.

Explicit Interface and Implicit Interface in OOP using C#

Interface in OOP using C#:

Now We will discuss about the two types of implementation od Interface in OOP, Implicit Implementation and Explicit Implementation.

Interface : Implicit Implementation:

If a class implements two interfaces
that contain a member with the same signature, then implementing that member on
the class will cause both interfaces to use that member as their
implementation. For example:

interfaceIControl //1st Interface

{

void
Paint();

}

interfaceISurface // 2nd Interface

{

void
Paint();

}

classSampleClass : IControl, ISurface //A Class inheriting both Interfaces at a time to implement

{

//
Both ISurface.Paint and IControl.Paint call
this method. means that if any interface object will cann Paint() method, the body of below Paint() method will be called

publicvoid
Paint()

{

}

}

Interface : Explicit Implementation:

If the two interface members do not
perform the same function, it is
possible to implement an interface member explicitly—creating a class member
that is only called through the interface, and is specific to that interface.

This is accomplished by naming the class
member with the name of the interface and a period. For example:

publicclassSampleClass : IControl, ISurface////A Class inheriting both Interfaces at a time to implement

{

voidIControl.Paint()// Specializing it for IControl Interface that if Object of IControl Interface Calls Paint() method ,

{

System.Console.WriteLine("IControl.Paint"); // if u have written "using System;" then wroting System here not necessary.