Difference between singleton and factory pattern

后端 未结 6 859
心在旅途
心在旅途 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条回答
  •  Happy的楠姐
    2020-12-07 09:53

    +---------------------------+-------------------------------+
    |         Singleton         |            Factory            |
    +---------------------------+-------------------------------+
    | Returns Same instance     | Returns various new instances |
    | Single Constructor hiding | Multiple Constructors expose  |
    | No interface              | Interface driven              |
    | No Subclasses             | Subclasses                    |
    +---------------------------+-------------------------------+
    

提交回复
热议问题