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

前端 未结 9 1755
既然无缘
既然无缘 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:11

    All I can think of for now:

    Pros:

    • Clear separation between interface and implementation
    • Reduced unit dependencies
    • Multiple inheritance
    • Reference counting (if desired, can be disabled)

    Cons:

    • Class and interface references cannot be mixed (at least with reference counting)
    • Getter and setter functions required for all properties
    • Reference counting does not work with circular references
    • Debugging difficulties (thanks to gabr and Warren for pointing that out)

提交回复
热议问题