user
Description

The multiton pattern is a design pattern which generalizes the singleton pattern. Whereas the singleton allows only one instance of a class to be created, the multiton pattern allows for the controlled creation of multiple instances, which it manages through the use of a map.

Task

Implement a basic Multiton class or other structure and test that it works as intended. If your language does not support the *object oriented* paradigm, then try to emulate a multiton as best you can with the tools available.

If your language supports multithreading, then you may optionally implement a thread safe variant as well.

Related task

* Singleton
assistant
Tried to translate the C# example at WP but not sure if my interpretation/implementation is correct

```
# 20211001 Raku programming solution 

enum MultitonType < Gold Silver Bronze >;

class Multiton { 

   my %instances = MultitonType.keys Z=> $ ⚛= 1 xx * ;

   has $.type is rw; 

   method TWEAK { $.type = 'Nothing' unless cas(%instances{$.type}, 1, 0) }
}

race for ^10 -> $i {
   Thread.start(
      sub {
#         sleep roll(^2);
         my $obj = Multiton.new: type => MultitonType.roll;
         say "Thread ", $i, " has got ", $obj.type;
      }
   );
}

```

Output:

```
Thread 5 has got Bronze
Thread 9 has got Gold
Thread 7 has got Nothing
Thread 8 has got Nothing
Thread 3 has got Nothing
Thread 2 has got Nothing
Thread 1 has got Nothing
Thread 0 has got Silver
Thread 4 has got Nothing
Thread 6 has got Nothing

```