What exactly is a Class Factory?

后端 未结 5 616
星月不相逢
星月不相逢 2020-12-01 04:38

I see the word thrown around often, and I may have used it myself in code and libraries over time, but I never really got it. In most write-ups I came across, they just went

5条回答
  •  悲哀的现实
    2020-12-01 05:11

    A class factory constructs instances of other classes. Typically, the classes they create share a common base class or interface, but derived classes are returned.

    For example, you could have a class factory that took a database connection string and returned a class implementing IDbConnection such as SqlConnection (class and interface from .Net)

提交回复
热议问题