單態(tài)模式(Singleton Pattern) 就是一個(gè)類Class只有一個(gè)實(shí)例存在。(Ensure a class only has one instance, and provide a global point of access to it.)
這個(gè)是php5的寫法。
| 以下為引用的內(nèi)容: <?php class SingletonPhp5{ static private $_instance=null; function getInstance(){ function __construct(){ } function Show(){ { |
這個(gè)是php4的寫法,當(dāng)然此方法在php5下也可以正常運(yùn)行。
| 以下為引用的內(nèi)容: class SingletonPhp4{ |
新聞熱點(diǎn)
疑難解答