O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

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

Use the Factory Pattern

Problem

You want the ability to create classes generically, without knowing their specific types.

Solution

Create a dedicated factory class that can construct the type of class you need.

Discussion

The factory pattern is one of the best-known creational patterns. It provides an abstracted mechanism for creating classes.

In the factory pattern, as shown in Figure 4-4, every class has its own corresponding factory class. In order for the factory pattern to work, all of these classes must derive from two abstract base classes.

The abstract factory pattern

Figure 4-4. The abstract factory pattern

For example, imagine you want to create a generic component that queries ...

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