The factory method and abstract factory patterns are creational patterns that encapsulate the instantiation of objects so that their representation and configuration can be kept away from the overall system design. These patterns are useful when we need to create the object without knowing the exact subclass it belongs to. For instance, we may have to construct a generic trade object before we know that it is a plain vanilla option.

The factory method pattern shown in the UML diagram in Figure 7.4 uses inheritance to construct the right kind of trade objects. It can accomplish it also through a parameterized factory method, which gets the information about the kind of trade to manufacture through an input parameter.


Figure 7.5 The abstract factory pattern. The UML diagram above illustrates its use in handling customer-facing trades and their hedging counterparts as parallel structures.

The abstract factory pattern is useful when handling parallel class structures. For instance, suppose we have a set of customer-facing trades and their hedging counterparts. We may want to switch the pricing model of all the customer-facing trades to a new one in one go. At the same time, we may want to reprice the hedging trades using a compatible new model as well. Thus we have class parallelism – two sets of trades and two models – setting the stage for development using the ...

Get Principles of Quantitative Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.