Menu
Kaivalya Techno Soft
  • Home
Kaivalya Techno Soft

How not to use interfaces in C#

Posted on May 9, 2019May 9, 2019

What are interfaces?

First off, let’s get an understanding of interfaces and why they are needed in programming. An interface is strictly a contract; it doesn’t have any implementation. An interface contains only member declarations. You can have method declarations but not definitions. The members declared in an interface should be implemented in the types (classes and structs) that extend or implement the interface. An interface cannot contain fields. An interface cannot be serialized because it cannot have data members. As I said, an interface can have only declarations and not definitions.  

Avoid making changes to interfaces 

A class or a struct that extends an interface should implement all of its members. If the implementation changes, your code will still work. However, if the contract, i.e., the interface, changes, then you’ll have to change the implementations of all types that extend the interface. In other words, any change to the interface will impact all of the types that extend the interface. The types extending the interface must adhere to the contract. So, use interfaces only when you rarely need to change them. Also, it’s generally better to create a new interface than change an existing one. 

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • You Have to See These Great Inventions!
  • Google Maps पर इस तरह अपने दोस्तों के साथ शेयर करें अपनी Real Time Location
  • ISRO Successfully Launches Earth Observation Satellite RISAT-2B
  • Google: Use Kotlin for new Android apps
  • How not to use interfaces in C#

Recent Comments

    Archives

    • May 2019

    Categories

    • Uncategorized

    Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
    ©2019 Kaivalya Techno Soft