design patterns - Singleton's consequence trouble -


i'm learning singleton pattern using gof's book. have problem when read it's consequence:

  • more flexible class operations: another way package singleton's functionality use class operations (that is, static member functions in c++ or class methods in smalltalk). both of these language techniques make hard change design allow more 1 instance of class. moreover, static member functions in c++ never virtual, subclasses can't override them polymorphically.

i don't understand explanation. think class operation (static method) can allow more 1 instance of class too, if use static list of instances, know i'm wrong, of course.

so, can give me examples me understand problem? much!

the original idea make use static members in class, , static methods operate on these static members, , use the class itself singleton. no runtime istantiation needed or allowed - , if istantiate anything, of type (an instance, not class. in smalltalk instance of class, , not instance of metaclass).

so, if manage list of such instances, did not create multiple instances of type; have created singleton (the class) have in it list of non-singleton-type instances.

in sense, every class singleton. it's not idea use 1 singleton object in program, reasons mentioned in text.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -