The WebAbility® Network Developers - Documentation
WebAbility Site
\patterns\Multiton reference

I. Structure:

- namespace:

- Direct superclass:

- Direct known subclasses:

II. Description:

This is a pattern derived from the singleton pattern, but the uniqueness is based on a parameter for each instance.
So there can be some instances of the same class, but none with the same parameter value.
When you intend to create a second instance of the class with the same parameter, an error is thrown.

The multiton have a static method to get or create the unique instance based on the parameter, easily without bothering where is the instance:
- getInstance($parameter, 'name_of_class') to get the unique parametered instance of your class.

You should extend all your multitons from the \patterns\Multiton class.
Be sure you call the constructor of your father class.


class Invoice extends \patterns\Multiton
function __construct($invoicenumber)

function printinvoice()

... Lots of your code ...

$firstinvoice = \patterns\Multiton::getInstance(1, 'Invoice');
$lastinvoice = \patterns\Multiton::getInstance(3382, 'Invoice');

... Use your multitons ...

III. Reference:

3.1. Contructor:

Creates the unique instance of your class based on the $parameter value.

3.2. Constants:

There is no constant into this class.

3.3. Attributes:

protected mixed $parameter:
Contains the value of the parameter of your multiton class.

3.4. Methods:

public static getInstance($parameter, $data)
This method is used to get the instance of the asked class based on the parameter.
If the instance does not exist yet, it will be create.
If the class does not exist, an error is thrown.