Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
Tests Merge branch 'master' into feature/class-instead-of-namespace Mar 9, 2017
uml Added Creational pattern UMLs Jul 31, 2014
README.rst Improve grammar: these code > this code Apr 4, 2017
Singleton.php PHP7 Singleton und Multiton Sep 22, 2016

README.rst

Singleton

THIS IS CONSIDERED TO BE AN ANTI-PATTERN! FOR BETTER TESTABILITY AND MAINTAINABILITY USE DEPENDENCY INJECTION!

Purpose

To have only one instance of this object in the application that will handle all calls.

Examples

  • DB Connector
  • Logger (may also be a Multiton if there are many log files for several purposes)
  • Lock file for the application (there is only one in the filesystem ...)

UML Diagram

Alt Singleton UML Diagram

Code

You can also find this code on GitHub

Singleton.php

.. literalinclude:: Singleton.php
   :language: php
   :linenos:

Test

Tests/SingletonTest.php

.. literalinclude:: Tests/SingletonTest.php
   :language: php
   :linenos: