PHP:Singleton与静态类

时间:2010-05-25 12:56:58

标签: php oop singleton static-methods

  

可能重复:
  Difference between static class and singleton pattern?

只是想知道单例和静态类的区别究竟是什么?

5 个答案:

答案 0 :(得分:6)

我认为这个问题已在这里得到解答:Difference between static class and singleton pattern?

答案 1 :(得分:3)

在单例中,您可以选择在第一次调用时初始化变量。而在您包含/调用声明静态变量的文件时,静态变量开始存在。

答案 2 :(得分:1)

Singleton是与特定语言的实现无关的模式。从技术上讲,singleton表示系统中只能有一个对象实例。如果是静态类,则根本不会有任何对象。

答案 3 :(得分:1)

单例和一堆静态方法之间的最大区别在于单例可以实现interfaces。但静态不会

Difference between static class and singleton pattern?

答案 4 :(得分:1)

单例是一种抽象设计模式,它描述了只能创建一次的对象。静态类是此设计模式的特定实现。