[Next] [Prev] [Up] [Top]

20.0 Design

Use the Abstract Factory pattern (GL)


Rather than embedding calls to "new" inside method bodies, designers should create a virtual method whose body is simply to return a new instance. This allows derived classes to override this "generator" method to create derived classes. This is called an Abstract Factory Pattern.

Example:

void X :: foo ()

{

...

Y* y = newY (xxx);

...

}

Y* X :: newY (args)

{

return new Y(args);

}


No Title
[Next] [Prev] [Up] [Top]

Generated with CERN WebMaker

This site was grabbed using the TRIAL version of Grab-a-Site. This message does not appear on a licensed copy of Grab-a-Site.