Difference between singleton and factory pattern

后端 未结 6 858
心在旅途
心在旅途 2020-12-07 09:41

I\'m new to design patterns and I cant really see a difference between this two patterns, both are creational patterns arent they? and what is the purpose of each pattern? t

6条回答
  •  萌比男神i
    2020-12-07 09:54

    The Singleton pattern ensures that only one instance of the class exists and typically provides a well-known, i.e., global point for accessing it.

    The Factory pattern defines an interface for creating objects (no limitation on how many) and usually abstracts the control of which class to instantiate.

提交回复
热议问题