C# Interface Tutorial with Example


C# Interface Tutorial with Example


The main point raises when we talk about Interface is a contract between 2 parties(caller and callee). and makes the alert to the developer.

if any method name changes happen accidentally. it helps to implement impact analysis in case we change any method in which places it will impact.

and it has different by-products like the below-mentioned list

  1. Multiple inheritances
  2. Signature
  3. Versioning
  4. Enforces rules
  5. Decoupling
  6. Abstraction (Show only what is necessary and hide unnecessary   methods)
  7. Standardization

What is Contract in the real world?

The contract is legally binding which two entities decided to follow on rules.

  if any one of them breaks the rule then that logic is not executed at the server.


We have 2 types of contracts 

  • Implicit Contract

                Here we directly using the reference in our project

  •  Explicit Contract

   Here we don't use the reference directly and going to decouple the code by using design patterns.

Main Advantages using the Interface:

  • Use an Interface explicit contract where 2 parties are decoupled from each other.
  • Abstraction (Show only what is necessary and hide unnecessary  methods)
  • we can find the great Impact Analysis in the build time.
  • we have great change detection in the build time
  • Multiple inheritances happen when we need a new extension without disturbing the existed code.

Some important Note:

The interface should not be changed once it goes to production.


 


Previous Post Next Post