[WEBINAR] Application Acceleration: Faster Performance for End Users

Interface Implementation

Definition - What does Interface Implementation mean?

Interface implementation, in C#, refers to the inheritance of an interface by a struct or class that provides the functionality for the members declared in the interface. The members of the implemented interface can include methods, properties, indexers and events.

In general, an interface represents a contract which has to be adhered by a class or struct that implements all the members specified in the interface. The key benefits of interface implementation include flexibility, low coupling, high cohesion and polymorphic behavior.

In C#, interface implementation allows a class to inherit from multiple interfaces instead of multiple classes so that more than one behavior can be inherited through multiple interfaces that share method signatures only. Interface can be implemented as property to specify whether the property is read-write, read-only or write-only. An interface can be implemented explicitly to hide a member and replace it with another. Unlike in Java, C#‘s explicit interface implementation allows multiple interfaces with same method name and signatures, to have different implementations without any name clash and provide different result based on the current cast of the object.

Techopedia explains Interface Implementation

Similar to an abstract class, an interface does not provide a default implementation. A member of a class or struct that implements a member of an interface must be public, non-static and possess the same name and signature as that in interface.

For example, an interface IAccount can be implemented by a class, SavingAccount which implements the members of IAccount that can include BalanceAmount, DateOfOpening, etc. as its properties and methods like PrintStatement, CalculateInterest, etc.

Interface implementation can be implicit when a base class of a derived class already implements the interface. All the base interfaces need not be explicitly specified in the base class list of the derived class. In addition, the derived class can change the interface behavior that has been defined already in the base class by overriding the virtual members in the derived class.

Interface implementation is explicit when members of two or more interfaces having same name with same signature but performing two different functions, are inherited by a class or struct that implements each member explicitly. Such a member is named with the name of the interface and a period and can only be accessed only through an instance of the interface. Unlike implicit methods, explicit methods cannot be abstract or virtual.

This definition was written in the context of C#

Techopedia Deals

Connect with us

Techopedia on Linkedin
Techopedia on Linkedin
"Techopedia" on Twitter

Sign up for Techopedia's Free Newsletter!

Email Newsletter

Join thousands of others with our weekly newsletter

Free Whitepaper: The Path to Hybrid Cloud
Free Whitepaper: The Path to Hybrid Cloud:
The Path to Hybrid Cloud: Intelligent Bursting To Amazon Web Services & Microsoft Azure
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.