﻿<?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>FAQ, The 'Gang of Four' Companion</title>
	<meta http-equiv="Content-Style-Type" content="text/css" />
	<meta name="Author" content="Amnon H Eden" />
</head>


<body>


<h5><a href="./index.xml">The 'Gang of Four' Companion:</a></h5>

<p class="pagetitle">Modelling Design Patterns: Frequently-Asked Questions</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> 
	which details the formal specification 
		of the Abstract Factory design pattern from the 'Gang of Four' catalogue [<a href="http://www.lepus.org.uk/ref/index.xml#bib">Gamma 
	et al 1995</a>].</p>
	<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>
	</ul>

	<p>Download:</p>
	
	<ul>
		<li><a href="../../spec/gof/lepus3/gof.vsd">The GoF patterns in LePUS3 (Visio 2003 format)</a></li>
	</ul>
</div> 

<doc:toc />

<h1>What are design patterns?</h1>

<p>Design patterns are 'recipe's for solving software design problems by 
	describing a particular <em>design motif</em>: a category of solutions to a 
	class of common design problems. <span lang="en-us">The most widely used kind of 
	design patterns are patterns of object-oriented design: recipes which describe a 
	category of problems common to object-oriented design and how they should be 
	solved. The excellent 'Gang of Four' catalogue [<a href="../index.xml#bib">Gamma 
	et al. 1995</a>] has established the widest practice of design patterns in 
	object-oriented design. A nice introduction to design patterns is offered in [</span><a href="../index.xml#bib">Schmidt 
	et al. 1996</a>] (<a href="http://www.cs.wustl.edu/~schmidt/CACM-editorial.html">available 
	online</a>).</p>
	
<p>Most often, however, a 'pattern' in the vernacular refers to the design motif 
	element of the design pattern<span lang="en-us">, </span>not to the recipe
	<span lang="en-us">as a whole</span>. While some see this as a confusion, others 
	consider this a natural by-product in the evolution of standard software design 
	solutions to common problems, such as <em>architectural styles </em>[<a href="../index.xml#bib">Garlan 
	&amp; Shaw 1993</a>], <em>programming paradigms</em>, and <em>component-based 
	software engineering</em> technologies<span lang="en-us"> </span>[<a href="../index.xml#bib">Szyperski&nbsp;
	<span lang="en-us">2002</span></a>].<span lang="en-us"> In LePUS3 and Class-Z we 
	adopt the common practice of using the term 'design pattern' (in short, 
	'pattern') with reference to the design motif that the pattern's recipe 
	describes.</span></p>
<h1>What is so special about modelling design patterns?</h1>
<p>Modelling languages in standard use, such as the Unified Modeling Language and its predecessors (e.g. Object Modeling Technique, Booch 
	Notation, etc.) are focused on modelling a particular software system&mdash;a 
	specific program (or a specific collection of programs). Design patterns however 
	are design motifs: there is usually an unbound number of programs that implement 
	each pattern. Modelling a design pattern is therefore an exercise in abstraction
	<em>cum</em> genericity: it requires the use of <em>
	<a href="../legend/legend.xml#Modelling_generic_motifs">variables</a></em> (as 
	opposed to <em>constants</em>) which range over a category of implementations.</p>
	<p>Why variables are so important? Try 'modelling' the difference 
	between the following two statements:</p>
<ol>
	<li>Class <code>java.awt.Container</code> extends class <code>java.awt.Component</code> </li>
	<li>A <classz:variable value="Composite" /> class (such as <code>java.awt.Container</code>) 
		must extend, either directly or indirectly, the <classz:variable value="Component" /> class (such as <code>java.awt.Component</code>). </li>
</ol>

<p>The first sentence describes a specific 
	implementation, the second describes a <em>design pattern</em>&mdash;a category of 
	implementations. The first statement determines the relation between specific 
	classes, whereas the second statement imposes a constraint on such classes. The first statement is 
	<a href="../refman/refman.xml#closed_spec">closed</a>, the second is 
	<a href="../refman/refman.xml#open_spec">open</a>.</p>

<h1>Why the focus on the 'Gang of Four' catalogue?</h1>
	<p>The book <i>Design Patterns: Elements of Reusable Object-Oriented Software</i> <span lang="en-us">
	[<a href="../index.xml#bib">Gamma 
	et al. 1995</a>] was authored by </span>Erich Gamma, Richard Helm, Ralph Johnson, 
	and John Vlissides, <span lang="en-us">a quartet which came to be known as the 
	'gang of four' (hence: the 'Gang of Four' Catalogue). The catalogue delivers a 
	meticulous description of twenty-three design patterns. Many of the patterns 
	described in the book have been implemented in a wide range of well-designed 
	programs and are currently recognized as paragons of good design.</span></p>

<p>For these reasons, <a href="./index.xml">The 'Gang of Four' Companion</a> is 
	focused on modelling the design patterns in the 'Gang of Four' catalogue.</p>

<h1>What's wrong with UML as a modelling language for design patterns?</h1>

<p>Giving a full answer to this question would require not one page but an 
	entire encyclopaedia. We are not in the business of writing the seven volume<em>s
	</em>of <em>What's Wrong with UML</em>; others have already done so successfully (see Bertrand's Meyer's excellent 
	<a href="http://www.eiffel.com/doc/manuals/technology/bmarticles/uml/page.html">
	UML&mdash;The Positive Spin</a>.) Rather, let us describe what mechanisms of LePUS3 
	and Class-Z are specifically tailored for modelling design patterns, <em>none of 
	which</em> applies to UML:</p>

<ul>
	<li><strong>Decidability &amp; Verification</strong>:<strong> </strong>All LePUS/Class-Z specifications are 
		decidable and can be verified automatically by a tool support (see also: <a href="http://ttp.essex.ac.uk/">
		The Two-Tier Programming Project</a>)</li>
	<li><strong>Rigour</strong>: Each LePUS3/Class-Z specification is equivalent 
		to a <a href="../refman/refman.xml#subsetsfopl">formula in first-order 
		classical predicate calculus</a>, and their
		<a href="../refman/refman.xml#Truth_conditions">semantics</a> is defined 
		using Tarski's style truth conditions in terms of finite models. </li>
		<li><strong>Abstraction viz. genericity</strong>: LePUS/Class-Z distinguish 
		between <em>
		<a href="../legend/legend.xml#Modelling_generic_motifs">variables</a></em>, 
		which range over (elements of) implementations, and <em>constants</em>, 
		modelling specific (elements of) implementations.</li>
	<li><strong>Abstraction<em> </em> viz. scalability</strong>: LePUS3/Class-Z offer 
		a range of abstraction mechanisms (e.g.,
		<a href="../legend/legend.xml#Modelling_specific_(sets_of-)classes_and_class_hierarchies">
		class hierarchies</a>,
		<a href="../legend/legend.xml#Modelling_specific_(sets_of-)methods">sets of 
		methods with same signature</a>), whereas UML Class diagrams are limited to 
		packages and classes.</li>
	<li><strong>Abstraction</strong> <strong>viz. information 
		neglect</strong>: If class/method/relation x is not modelled, what does it 
		mean: That there is no such an entity? Or that it may or may not exist? In 
		LePUS3/Class-Z, absence of information indicates nothing, and specifications 
		merely impose constraints on the implementation but do not dictate it.</li>
</ul>

<p>&quot;But UML is so popular?!&quot;--right.</p>

<h1>Can LePUS3/Class-Z model everything about patterns?</h1>

<p>No. The syntax of LePUS3/Class-Z is <a href="../refman/refman.xml#Formulas">
	extremely limited</a>, allowing only for three kinds of
	<a href="../refman/refman.xml#Predicates">predicates</a> and only one kind of
	<a href="../refman/refman.xml#satisfaction_ground">ground formula</a>. 
	Furthermore, only decidable relations can be expressed using LePUS3 and Class-Z. 
	Therefore we cannot model statements such as 'each instance of class X holds 
	exactly 3 instances of class Y at each point in time.' Objects are not modelled 
	directly using LePUS3 and Class-Z, only classes.</p>

<p>Nonetheless, you would be surprised how much about patterns can be captured 
	with these simple concepts. <a href="index.xml">See here</a> the full list of 
	the 'Gang of Four' patterns that can be modelled in LePUS3/Class-Z.</p>

<h1>Which patterns can be modelled with LePUS3/Class-Z?</h1>

<p><a href="index.xml">See here</a> the full list of the 'Gang of Four' patterns 
	that can be modelled in LePUS3/Class-Z.</p>

<h1>Which other modelling languages for design patterns exist?</h1>

<p>There are many attempts to tailor formal specification languages specifically 
	for the purpose of modelling design patterns. Many of these efforts are listed
	<a target="_blank" href="http://www.eden-study.org/precise_and_formal">in this 
	page</a>. </p>

<h1>Why did you convert the original diagrams to UML and how?</h1>

<p>Each 'Structure' diagram in our '<a href="index.xml">Gang of Four Companion</a>' 
	includes UML Class Diagrams for illustrating the informal description, although 
	OMT was used by the [Gamma et al. 1995] catalogue. We could not quote the 
	original OMT diagrams due to copyright issues, and UML is currently much more 
	popular.</p>
	
<p>UML Class diagrams were created in Visio 2003 format (<a href="../../spec/gof/uml/gof.vsd">download 
UML Class Diagrams of the 'Gang of Four' design patterns</a>.)</p>
<p>The 'conversion' process is free-style for illustrative purposes only: namely 
	to show the inadequacy of UML in modelling each pattern. Don't write us about so called 
	'errors' in the UML Class Diagrams; we could not care less about those because
	<a href="#What's_wrong_with_UML_as_a_modelling_language_for_design_patterns?">
	neither UML nor OMT is any good for modelling design patterns anyway.</a></p>

</body>
</html>
