Using Interface variables

后端 未结 12 1136
广开言路
广开言路 2020-11-28 05:01

I\'m still trying to get a better understanding of Interfaces. I know about what they are and how to implement them in classes.

What I don\'t understand is when you

12条回答
  •  鱼传尺愫
    2020-11-28 05:37

    This is a fundamental concept in object-oriented programming -- polymorphism. (wikipedia)

    The short answer is that by using the interface in Class A, you can give Class A any implementation of IMyInterface.

    This is also a form of loose coupling (wikipedia) -- where you have many classes, but they do not rely explicitly on one another -- only on an abstract notion of the set of properties and methods that they provide (the interface).

提交回复
热议问题