O'Reilly logo

Microsoft® Visual Basic® 2010 Developer’s Handbook by Klaus Löffelmann and Sarika Calla Purohit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Singleton Classes and Self-Instantiating Classes

Assume you want to design a class to facilitate output to the screen or printer. What’s special in this case is that you must have control over the instantiation of this class. It’s not enough to leave the number of instantiations to the class itself. After all, a certain printer exists only once, and can’t have multiple instances of the same class in memory.

An abstract class with static procedures (or a module) could possibly be an alternative, but the problem is that neither the functions of a module nor the static function of an abstract class can be overridden in other classes.

The solution is Singleton classes. Unlike the different variants of classes to which you have been introduced so far, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required