'; ?> DomCore Demos, a WebAbility® Network Project
« Back to the index

\patterns\Multiton example

parameter; } } print "Let's get our first multiton instance:
"; print "You can get it with a \$M = new myM(10); but this can make an error, you never know if the instance already exists or not. getInstance is the method to use.
"; $M = \patterns\Multiton::getInstance(10, 'myM'); // This is equivalent to $M = myM::getInstance(10); print "A result with our multiton ".$M->getData() . "
"; print "Let's a second multiton instance:
"; $M = \patterns\Multiton::getInstance(15, 'myM'); print "A result with our new multiton ".$M->getData() . "
"; print "Let's get back the first multiton instance:
"; $M = \patterns\Multiton::getInstance(10, 'myM'); print "A result with our first multiton ".$M->getData() . "
"; print "Let's try to duplicate a multiton instance and get an error:
"; $M2 = new myM(10); // this can make an error too: $M2 = clone $M; ?>



« Back to the index