Substitutable Factories


One of the great benefits of using factories is the ability to substitute one implementation of a factory for another. In this way, you can substitute families of objects within an application.

For example, imagine an application that had to adapt to many different database implementations. In our example, let's assume that the users can either use flat files or purchase an Oracle adapter. We might use the PROXY pattern to isolate the application from the database implementation.[2] We might also use factories to instantiate the proxies. Figure 29-3 shows the structure.

[2] We'll study PROXY in Chapter 34. Right now, all you need to know is that a Proxy is a class that knows how to read particular objects out of particular kinds of databases.

Figure 29-3. Substitutable factory


Note the two implementations of EmployeeFactory. One creates proxies that work with flat files, and the other creates proxies that work with Oracle. Note also that the application does not know or care which implementation is being used.




Agile Principles, Patterns, and Practices in C#
Agile Principles, Patterns, and Practices in C#
ISBN: 0131857258
EAN: 2147483647
Year: 2006
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net