What exactly is “interface based programming”?

后端 未结 8 1704
有刺的猬
有刺的猬 2020-12-02 14:46

I often hear/read about interfaced based programming but I am not exactly clear on what that really means. Is interfaced based programming an actual stand alone topic that

相关标签:
8条回答
  • 2020-12-02 15:33

    Interface based programming can be thought of as decoupling the implementation of functionality and how you access the functionality.

    You define an interface
    interface ICallSomeone { public bool DialNumber(string number); }

    and you write your implementation

    public class callsomeone: ICallSomeone {
    public bool DialNumber(string number) {
    //dial number, return results }}

    You use the interface without caring about the implementation. If you change the implementation, nothing cares because it just uses the interface.

    0 讨论(0)
  • 2020-12-02 15:35

    Chapter 6 of "Practical API Design" by Jaroslav Tulach is titled "Code Against Interfaces, Not Implementations". It explains that, by coding against an interface rather than a specific implementation, you can decouple modules (or components) in a system and therefore raise the system quality.

    Bertrand Meyer in OOSC2 explains clearly why "closing" a system and making it more modular raises its quality.

    0 讨论(0)
提交回复
热议问题