Useless interfaces

后端 未结 25 1660
南笙
南笙 2020-12-14 01:42

Why would you ever use an interface if you are only going to have one implementation of it?

25条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 02:44

    Yes, especially with Delphi.

    If you have an interface reference to a object then you get reference counting automatically. So it is really common to have an interface with only one implementation when you want the object to be cleaned up automatically. Reference counting is better than garbage collecting since the object's destructor is called as soon as the last reference either goes out of scope or is no longer referencing it.

提交回复
热议问题