november 27, 2002paper presentation of course c625, university of alberta generative design patterns...
Post on 20-Dec-2015
218 views
TRANSCRIPT
November 27, 2002Paper Presentation of Course C625, University of
Alberta
Generative Design PatternsGenerative Design Patterns
S. MacDonald, D. Szafron, J. Schaeffer, J. Anvik, S. Bromling and K. Tan
Department of Computing Science, University of Alberta
Speaker: Lihang Ying ([email protected])
Generative Design Patterns
What’s the paper about?What’s the paper about?
Example – Visual C++ 6.0
Generative Design Patterns
Example – Visual C++(1)Example – Visual C++(1)
Select a template:
Generative Design Patterns
Example – Visual C++(2)Example – Visual C++(2)
Select application’s type:
Generative Design Patterns
Example – Visual C++(3)Example – Visual C++(3)
Specilize the application:
Generative Design Patterns
Example – Visual C++(4)Example – Visual C++(4)
Set class names:
Generative Design Patterns
Example – Visual C++(5)Example – Visual C++(5)
Generate code:
Generative Design Patterns
Example – Visual C++(6)Example – Visual C++(6)
Compile and run it!(without any coding)
Generative Design Patterns
Example – Visual C++(7)Example – Visual C++(7)
Modify component’s properties:
Generative Design Patterns
Example – Visual C++(8)Example – Visual C++(8)
Add method for the button-click event:
Generative Design Patterns
Example – Visual C++(9)Example – Visual C++(9)
Edit member functions:
Generative Design Patterns
Example – Visual C++(10)Example – Visual C++(10)
Final application:
Think about implement it using Win API, Motif, GTK
– Time consuming– Mechanical
Generative Design Patterns
Conclusions from the Conclusions from the example(1)example(1) Trend of software developing:
– Visual Design– Automatic Programming
Ideas:– Stupid and never-tired computer: do the
mechanical and repeated things – Intelligent Human: do creative design
Also applicable for computer science.
Generative Design Patterns
Conclusions from the Conclusions from the example(2)example(2) Characters of this example:
– Visual design of GUI– Create framework automatically
• Adaptation
– Focus on design, instead of coding
Limitations:– Can’t create application template– Can’t design hiberarchy of classes graphically
Generative Design Patterns
What does this paper focus on?What does this paper focus on?
Visual design of whole application– Class– Control flow
Create framework of code automatically, with adaptation
Can create and edit template
Generative Design Patterns
OutlineOutline
1. Introduction1.1 What’s the paper about?
1.2 Motivation
1.3 Contributions of this paper
2. Generative Design Pattern
3. Summary
Generative Design Patterns
1.2 Motivation(1)1.2 Motivation(1)
Many applications share a common structure:
– GUI, as mentioned in the previous VC example
– Parallel Programming:• parallel programmers have a set of common
structures that they start with when creating a new program, such as fork/join parallelism, pipelines, work farms, and meshes.
Generative Design Patterns
Motivation(2)Motivation(2)
This common structure can be abstracted out.
This idea is called “Design Patterns”
Generative Design Patterns
What’s a pattern?What’s a pattern?
provides a sketch of the solution structure in a generic form
can be adapted for a family of problems
contrast to API library, reuses – the application-independent structural
code– the complete design of the application.
Generative Design Patterns
OutlineOutline
1. Introduction1.1 What’s the paper about?
1.2 Motivation
1.3 Contributions of this paper
2. Generative Design Pattern
3. Summary
Generative Design Patterns
1.3 Contributions of this 1.3 Contributions of this paper(1) paper(1) Published descriptive design patterns
– Include:• lists of participants• implementation issues• sample code.
– These three parts of the pattern are used most when implementing a design pattern manually. However, they are not sufficient for generative design patterns.
Generative Design Patterns
1.3 Contributions of this 1.3 Contributions of this paper(2) paper(2) The key novel contributions of this paper:
– Quantify each adaptation option as a parameter with a fixed set of possible values that must be set during the initial adaptation process.
Although the specific parameters vary from design pattern to design pattern, the parameters can be classified into a few distinct types.
Generative Design Patterns
OutlineOutline
1. Introduction
2. Generative Design Pattern 2.1 General Description
2.2 Design Pattern Adaptation
2.3 Constructing generative patterns
3. Summary
Generative Design Patterns
2.1 General Description - 2.1 General Description - Flow(1)Flow(1)
Generative Design Patterns
Flow(2)Flow(2)
Generative Pattern Description– Holds all of information needed by a
programming tool to incorporate the generative pattern
Generative Pattern Generator– processes the Parameter Descriptions and
(optionally) the Graphical Representation and outputs a Generative Pattern
Generative Design Patterns
Flow(3)Flow(3)
Code Generator – takes User-supplied Parameter Values and the
Source Code Template and produces a customized framework(Framework Code) implementing the selected pattern structure.
Framework code– consists of Structural Code and Hook Methods.
The user creates an application by supplying Application-specific Code for the hook methods exported by the framework.
Generative Design Patterns
Tool support and key issuesTool support and key issues
‘CO2P2S’– adapt design patterns by providing parameter
values.– generate framework code for use in specific
applications.
‘Meta-CO2P2S’– create new generative design patterns– generate tool-independent representations – edit and evolve existing design patterns.
Generative Design Patterns
Three steps of developingThree steps of developing
Select an appropriate generative design pattern from a set of available patterns.
Adapt this pattern for their application by providing parameter values.
Use the adapted generative pattern to create object-oriented framework code for the chosen pattern structure.
Generative Design Patterns
How to represent generative How to represent generative pattern?(1)pattern?(1)Pattern parameter representation:
– Using XML• XML format is tool-independence• The format of an XML file can be verified
by a DTD(Document Type Definition) file. No custom verifier is required.
• System-independence support tools for parsing and manipulating XML files are available.
Generative Design Patterns
How to represent generative How to represent generative pattern?(2)pattern?(2)Framework representation
– Source code template• A template is a set of annotated source code
files, where the annotations indicate how the generative pattern parameters alter the code.
Generative Design Patterns
OutlineOutline
1. Introduction
2. Generative Design Pattern 2.1 General Description
2.2 Design Pattern Adaptation
2.3 Constructing generative patterns
3. Summary
Generative Design Patterns
2.2 Design Pattern Adaptation2.2 Design Pattern Adaptation
The key of adaptation: – parameter-based
7 Parameters:– 4 lexical parameters– 2 design parameters– 1 performance parameter
Example: ‘Composite Design Pattern’
Generative Design Patterns
Composite Design Pattern(1)Composite Design Pattern(1)
Individual parts(leaf class) and compositions of parts(composite class) are treated uniformly
Support hierarchy ‘traversal operations’– Leaf class
• implements each traversal operation as local operation
– Composite class • implements the traversal operation optionally• With calls that apply the same operation to each of its child
objects.
Child management operations:– add(), remove()
Generative Design Patterns
What does What does traversal operationtraversal operation mean?mean?
Generative Design Patterns
Example: a drawing Example: a drawing applicationapplication Leaf classes:
– Line– Circle
Composite classes:– Group: an arbitrary collection of other components,
i.e. Line , Circle or other composite classes– Quadrilateral: a specific collection of four lines
Traversal operations:– draw(GraphicsContext)– boundingBox()
Generative Design Patterns
Parameters(1)Parameters(1)
Lexical Parameters:– Component(Abstract Component Class):
• ‘DrawingComponent’
– Composite(Abstract Composite Class): • ‘ListComposite’ -- Group• ‘FourComposite’ -- Quadrilateral
– Leaf(Abstract Leaf Class):• ‘Drawingleaf’
– Superclass:• ‘Object’ in Java / Empty in C++
Generative Design Patterns
Parameters(2)Parameters(2)
Design Parameters:– Safe-transparent
• Type: Enumeration– Safe– Transparent
– Operation list• Type: List
– draw(GraphicsContext)– boundingBox()– …
Generative Design Patterns
Parameters(3)Parameters(3)
Performance Parameter:– Container:
• Store child components• Type: Dictionary
– Entry 0: • ‘ListComposite’ [Type:List]
– Entry 1:• ‘FourComposite’ [Type:Four Children]
Generative Design Patterns
DiagramDiagram
Generative Design Patterns
More on Operation List More on Operation List Element(1)Element(1)Type: Structure
– Signature– Prefix(Type: Structure)– Suffix(Type:Structure)
Generative Design Patterns
More on Operation List More on Operation List Element(2)Element(2)draw(GraphicsContext): prefix method
– A composite instance must draw a background(drawBackground()) before calling the draw(GraphicsContext) method on each of its children to draw the foreground.
– drawBackground() is called before traversing the child instances.
Generative Design Patterns
More on Operation List More on Operation List Element(3)Element(3) Signature:
– void draw(GraphicsContext gc)
Prefix:– Signature: void drawBackground(GraphicsContext gc)– Prefix– suffix
Suffix:– (empty)
Generative Design Patterns
More on Operation List More on Operation List Element(4)Element(4)boundingBox(): suffix method
– Each composite instance must invoke this method on each of its children and then use the results to construct a bounding box from all of the Rectangle objects that are returned from the children.
– Such a method is called a suffix method
Generative Design Patterns
More on Operation List More on Operation List Element(5)Element(5) Signature:
– Rectangle boundingBox()
Prefix:– (empty)
Suffix:– Signature:
• Rectangle computeBoundingBox(Rectangle[] anArray)
– Prefix– Suffix
Generative Design Patterns
Further adaptation(1)Further adaptation(1)
After parameter value specification, the adapted design pattern is used to generate a code framework.
Further adaptation using framework specialization
Generative Design Patterns
Further adaptation(2)Further adaptation(2)
Create subclasses:– DrawingLeaf
• Line• Circle
– ListComposite• Group
– FourComposite• Quadrilateral
Generative Design Patterns
Further adaptation(3)Further adaptation(3)
Every classes need to call traversal operation
‘Group’ and ‘Quadrilateral’:– Inherit(skip to do anything):
• draw(GraphicsContext)• boundingBox()
– Implement:• drawBackgroundBox(GraphicsContext)• computeBoundingBox(Rectangle[])
Generative Design Patterns
Further adaptation(4)Further adaptation(4)
‘Line’ and ‘Circle’:– Implement:
• draw(GraphicsContext)• boundingBox()
Generative Design Patterns
Section SummarySection Summary
Component:– DrawingComponent
Leaf:– DrawingLeaf
• Line• Circle
Composite:– Group,Quadrilateral
Operation:– draw()– boundingBox()
Generative Design Patterns
OutlineOutline
1. Introduction
2. Generative Design Pattern 2.1 General Description
2.2 Design Pattern Adaptation
2.3 Constructing generative patterns
3. Summary
Generative Design Patterns
2.3 Constructing generative p2.3 Constructing generative patternsatternsDefine each parameter and its
parameter typeSupport information that can be used
to generate a graphical user interface– Label– Image– Layout information
Generative Design Patterns
Parameter typesParameter types
the parameters can be classified into a few distinct types
Generative Design Patterns
Framework generationFramework generation
After a pattern user specifies values for all of the parameters, the set of values is used to generate object oriented framework code.
It’s a problem of conditional compilation of a code template, based on the set of parameter values. Two issues:– Represent each parameter in the code template– Transform each parameter to concrete code. [skip details]
Generative Design Patterns
Using ‘Javadoc’ for code geneUsing ‘Javadoc’ for code generation(1)ration(1) Original purpose:
– Generate HTML formatted API document for Java classes Characters:
– Parse the declarations of Java source code– Parse specially formatted comment blocks
• Start with /**• End with */• Include lines that contain a tag name(@identifier)• Are followed on the next line by a declaration of class, field or met
hod
– Support pluggable Doclets
Generative Design Patterns
Using ‘Javadoc’ for code geneUsing ‘Javadoc’ for code generation(2)ration(2)
Generative Design Patterns
Using ‘Javadoc’ for code geneUsing ‘Javadoc’ for code generation(3)ration(3)Our solution for code generation(1)
– Class skeleton:• Use ‘javadoc’ to parse the code template• Write a Doclet which replaces the corresponding sl
ots using the parse result
Generative Design Patterns
Using ‘Javadoc’ for code geneUsing ‘Javadoc’ for code generation(4)ration(4)Our solution for code generation(2)
– Method bodies:• Written a small macro processor to support code
generation inside method bodies• Separate the bodies of all methods from the
methods• Code template consists of:
– A class skeleton file with empty method bodies– A directory of files, one for each method body
Generative Design Patterns
OutlineOutline
1. Introduction
2. Generative Design Pattern 2.1 General Description
2.2 Design Pattern Adaptation
2.3 Constructing generative patterns
3. Summary
Generative Design Patterns
3 Summary(1)3 Summary(1)
Flow
Generative Design Patterns
3 Summary(2)3 Summary(2)
Four steps of using a generative design pattern to write an application:– 1. Pick an appropriate set of design patterns.– 2. Use a tool like CO2P2S to adapt design patterns to
an application by selecting values for the pattern parameters.
– 3. Press a button to generate frameworks for each design pattern that has been customized for your application.
– 4. Use framework specialization to finish the application.
Generative Design Patterns
3 Summary(3)3 Summary(3)
Four steps of creating a new generative design pattern:– 1. Find an existing descriptive design pattern that
applies or create a new descriptive design pattern.– 2. Analyze the descriptive design pattern. If possible,
find an existing generative design pattern that is similar and edit it, instead of creating a new one.
– 3. Determine the legal parameter values– 4. Construct a code template that spans the legal
parameter values defined in 3).
Generative Design Patterns
3 Summary(4)3 Summary(4)
Software engineering(waterfall model) CASE Tools:
Support Seamless Link
Commercial Product:Rational ROSE
(Figure from “©Ian Sommerville, Software Engineering, 6th edition”)
Generative Design Patterns
The EndThe End
Thank you!