What exactly is “interface based programming”?

后端 未结 8 1742
有刺的猬
有刺的猬 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:27

    What you refer to as "interface based programming" is more commonly referred to as programming to an interface. Here is an example below. The benefit is hiding the actual implementation of the interface and allowing your code to be more flexible and easily maintained in the future.

    YourInterface foo = CreateYourInterface();
    foo.DoWork();
    foo.DoMoreWork();
    

    CreateYourInterface() would return a concrete implementation of YourInterface. This allows you to change the functionality of the application by changing one line:

    YourInterface foo = CreateYourInterface();
    

提交回复
热议问题