Implementing Factory Methods
A subject indirectly related to Singleton objects is the use of factory methods. From the last chapter, you know that the Singleton idiom is implemented by using a shared method to ensure the creation of one object, and defining a private constructor to ensure external consumers can't create objects without the help method. These helper methods are often referred to as factory methods.
A factory method is a shared method whose job it is to create instances of objects. Factory methods are used to instantiate Singleton objects, and are used to orchestrate object construction to facilitate the proper initialization of objects. A perfect example of a factory method is the CreateGraphics method. You can't instantiate a ...
Get Visual Basic® .NET Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.