Benefits of implementing an interface

后端 未结 10 1110
小鲜肉
小鲜肉 2020-12-06 04:58

what are the benefits of implementing an interface in C# 3.5 ?

10条回答
  •  无人及你
    2020-12-06 05:45

    The main benefits of interfaces is mostly related to project design.

    If you use an interface:

    1. The consumer of the interface should implement that interface.
    2. Designing bridge patters.
    3. Creating a contract so that user must adhere the rules of the interface.
    4. Can take only interface part (Object) from the main class.
    5. Even class is private, can obtain the interface object from that
    6. Multiple inheritance kind of style.
    7. Need not be should implement, simple go for if implements that means if you want you can implement other wise can drop it..
    8. Cleaner code.
    9. Implementation which changes depends on class can go ahead with interface.
    10. If each class have separate implementation of a method better to go for interfaces. For example IEnumerable in collections.

    According to C# Architect, in a simple word it's a contract. Consumer must adhere to it.

提交回复
热议问题