﻿<?xml-stylesheet type="text/xsl" href="../../templates/doc.xsl"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
<html 
	xmlns="http://www.w3.org/1999/xhtml" 
	xmlns:doc="http://www.lepus.org.uk/doc" 
	xmlns:classz="http://www.lepus.org.uk/classz" 
	xmlns:fopl="http://www.lepus.org.uk/fopl" 
	xml:lang="EN-GB" 
	xmlns:v="urn:schemas-microsoft-com:vml" 
	xmlns:o="urn:schemas-microsoft-com:office:office">

<head>
	<link rel="stylesheet" type="text/css" href="../../templates/doc.css" />
	<title>Abstract Factory pattern: The LePUS3 &amp; Class-Z companion to the GoF</title>
	<meta http-equiv="Content-Style-Type" content="text/css" />
	<meta name="Author" content="Amnon H Eden" />
	<style type="text/css">
.style1 {
	background-color: #FFFFFF;
}
</style>
</head>


<body>


<h5><a href="./index.xml">The 'Gang of Four' Companion:</a></h5>

<p class="pagetitle">Abstract Factory Design Pattern</p>

<h5><a href="./index.xml">Formal specification of design patterns in LePUS3 and Class-Z</a></h5>

<p><a href="companion.pdf" style="border:0px">
	<img alt="Print this document" src="../../site/print.gif" /></a></p>

<div class="abstract">

	<p>This page is part of the <a href="./index.xml">The 'Gang of Four' Companion</a> 
	dedicated to the formal specification in LePUS3 and Class-Z of patterns from the 'Gang of Four' catalogue [<a href="http://www.lepus.org.uk/ref/index.xml#bib">Gamma 
	et al 1995</a>].</p>

</div> <!-- Abstract-->

<doc:toc />

<h3>Links</h3>

<div class="abstract">

<ul>
		<li><a href="../legend/legend.xml">Legend: Key to LePUS3 and Class-Z Symbols</a></li>
		<li><a href="ref/refman/refman.xml">Reference Manual for LePUS3 &amp; Class-Z </a></li>
		<li><a href="faq.xml">Modelling Design Patterns: Frequently-Asked Questions</a></li>
	</ul>

	<p>Download:</p>
	
	<ul>
		<li><a href="../../spec/gof/lepus3/gof.vsd">The 'gang of four' patterns in LePUS3 (Visio 2003 format)</a></li>
		<li><a href="../../spec/gof/uml/gof.vsd">The 'gang of four' patterns in UML (Visio 2003 format)</a></li>
	</ul>
	
</div> <!-- Links -->


<h1>The Abstract Factory design motif</h1>

<p>The informal description: Excerpts from [<a href="../index.xml#bib">Gamma et al. 1995</a>] (adapted for 
	this purpose):</p>

<p><strong>Intent</strong>:<strong> </strong>Provide an interface for creating families of related or dependent objects 
	without specifying their concrete classes.</p>
	
<p><strong>Structure</strong>: Original OMT diagram converted to UML (<a href="faq.xml#Why_did_you_convert_the_original_diagrams_to_UML_and_how?">Why 
	and How?</a>):</p>

<img alt="Abstract Factory in UML" src="../../spec/gof/uml/AbstractFactory.png" /> <br />

<p><strong>Participants</strong>: </p>
<ul>
	<li><b>AbstractFactory</b> (WidgetFactory): declares an interface for operations that create abstract product objects.</li>
	<li><b>ConcreteFactory</b> (MotifWidgetFactory, PMWidgetFactory): implements the operations to create concrete product objects.</li>
	<li><b>AbstractProduct</b> (Window, ScrollBar): declares an interface for a type of product object.</li>
	<li><b>ConcreteProduct</b> (MotifWindow, MotifScrollBar): defines a product object to be created by the corresponding concrete factory; implements the AbstractProduct interface.</li>
</ul>

<p><strong>Collaborations</strong>: AbstractFactory defers creation of product objects to its ConcreteFactory subclass.</p>

<h1>Formal specification</h1>
<p>See also:</p>
<ul>
		<li><a href="../legend/legend.xml">Legend: Key to LePUS3 and Class-Z Symbols</a></li>
		<li><a href="ref/refman/refman.xml">Reference Manual for LePUS3 &amp; Class-Z </a></li>
		<li><a href="../../spec/gof/classz/AbstractFactory.xml">Abstract Factory in XML</a></li>
		<li><a href="faq.xml">Modelling Design Patterns: Frequently-Asked Questions</a></li>
	</ul>

<table class="chartandschema">
<tr>
	<td><img class="chart" id="AbstractFactory" alt="Abstract Factory in LePUS3" src="../../spec/gof/lepus3/AbstractFactory.png" /></td>
</tr>
<tr>
	<th>Abstract Factory in LePUS3 (<a href="../legend/legend.xml">legend</a>)</th>
</tr>
<tr>
	<td><doc:include value="../../spec/gof/classz/AbstractFactory.xml" /></td>
</tr>
<tr>
	<th>Abstract Factory in Class-Z (<a href="../legend/legend.xml">legend</a>)</th>
</tr>
</table>


<h1>Sample Implementations</h1>

<h2>Informal description: Widget Factories</h2>
<p>The example of cross-platform factories of graphical user interface widgets 
is described in [Gamma et. al 1995] as follows:</p>

<blockquote>Consider a user interface toolkit that supports multiple look-and-feel 
	standards, such as Motif and Presentation Manager. Different look-and-feels define 
	different appearances and behaviors for user interface "widgets" like scroll bars, 
	windows, and buttons. To be portable across look-and-feel standards, an application 
	should not hard-code its widgets for a particular look and feel. Instantiating 
	look-and-feel-specific classes of widgets throughout the application makes it hard 
	to change the look and feel later.
</blockquote>

<blockquote>We can solve this problem by defining an abstract WidgetFactory class that 
	declares an interface for creating each basic kind of widget. There's also an 
	abstract class for each kind of widget, and concrete subclasses implement widgets 
	for specific look-and-feel standards. WidgetFactory's interface has an operation that 
	returns a new widget object for each abstract widget class. Clients call these 
	operations to obtain widget instances, but clients aren't aware of the concrete classes 
	they're using. Thus clients stay independent of the prevailing look and feel.
</blockquote>

<h2>Formal specification: Widget Factory</h2>

<p>Specified in LePUS3 and Class-Z (see <a href="../legend/legend.xml">legend</a>)</p>

<table class="chartandschema">
<tr>
	<td><img class="chart" alt="Abstract factory Instance" src="../../spec/closed/AbsFacImp/AF-2dimHrc.gif" /></td>
</tr>
<tr>
	<th>Widget f<span class="style1">actory example </span>modelled in LePUS3<br />
			using 1 and 2-dimensional hierarchy constants (<a href="../legend/legend.xml">legend</a>)</th>
</tr>
<tr>
	<td><img class="chart" alt="" src="../../spec/closed/AbsFacImp/AF-1dimHrc.gif" /></td>
</tr>
<tr>
	<th>Widget f<span class="style1">actory example </span>modelled in LePUS3 <br />
			using 1-dimensional hierarchy constants (<a href="../legend/legend.xml">legend</a>)</th>
</tr>
<tr>
	<td><img class="chart" alt="" src="../../spec/closed/AbsFacImp/AF-0dim.gif" /></td>
</tr>
<tr>
	<th>Widget f<span class="style1">actory example </span>modelled in LePUS3<br />
			using 0-dimensional class and signature constants (<a href="../legend/legend.xml">legend</a>)</th>
</tr>
</table>


</body>
</html>
