CSC 480 Software Engineering Lab 5 – Abstract Factory Pattern Oct 30, 2002
CSC /30/2002 The Abstract Factory Pattern Intent – provide an interface for creating families of related or depended objects without specifying their concrete classes AKA Kit Like other creational patterns, this pattern can help to avoid hard-coding the way in which objects need to be created
CSC /30/2002 Design Pattern Space
CSC /30/2002 Structure – an illustration
CSC /30/2002 Application – pluggable look-and-feel Support multiple look-and-feel user interfaces, such as Windows, Motif, Macintosh Specify the selected look-and-feel in client programs The corresponding GUI factory will be returned to generate graphical components in the requested laf In Java, this is accomplished at the system level UIManager.setLookAndFeel(plafName);
CSC /30/2002 Look-and-Feel Alternatives Windows Motif Metal (swing’s default)
CSC /30/2002 Application in This Lab A GardenMaker Factory Garden varieties: annual, perennial, vegetable Common concerns What are good center plants? What are good border plants? What do well in partial shade? Plants With a name Other properties can be added
CSC /30/2002 Major Classes
CSC /30/2002 Sample Results
CSC /30/2002 Consequences Benefits It isolates concrete classes at the client level A factory encapsulates the responsibility and the process of creating product objects. Clients are isolated from implementation classes It makes exchanging product families easy – the concrete factory is used once It promotes consistency among products Liabilities supporting new kinds of products is difficult