What are the pros and cons of using interfaces in Delphi?

前端 未结 9 1650
既然无缘
既然无缘 2021-01-31 17:21

I have used Delphi classes for a while now but never really got into using interfaces. I already have read a bit about them but want to learn more.

I would like to hear

9条回答
  •  忘了有多久
    2021-01-31 18:12

    Interfaces solves a certain kind of issues. The primary function is to... well, ...define interfaces. To distinguish between definition and implementation.

    When you want to specify or check if a class supports a set of methods - use interfaces.

    You cannot do that in any other way.

    (If all classes inherits from the same base class, then an abstract class will define the interface. But when you are dealing with different class hierarchies, you need interfaces to define the methods thy have in common...)

提交回复
热议问题