generative design pattern source : 17th ieee international conference on automated software...

49
Generative Design Pattern Source Source 17th IEEE International 17th IEEE International Conference on Conference on Automated Automated Software Engineering, Software Engineering, Edinburgh, U.K., Edinburgh, U.K., September 23-27, 2002. September 23-27, 2002. Author Author S. MacDonald, D. Szafron, S. MacDonald, D. Szafron, J.Schaeffer, J. J.Schaeffer, J. Anvik, S. Bromling Anvik, S. Bromling and K. Tan and K. Tan Student Student Chih-Kun Chang Chih-Kun Chang

Upload: darren-logan

Post on 18-Jan-2016

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Generative Design Pattern

Source Source :: 17th IEEE International Conference on 17th IEEE International Conference on

Automated Software Engineering, Automated Software Engineering,

Edinburgh, U.K., September 23-27, 2002.Edinburgh, U.K., September 23-27, 2002.

AuthorAuthor :: S. MacDonald, D. Szafron, J.Schaeffer, J. S. MacDonald, D. Szafron, J.Schaeffer, J.

Anvik, S. Bromling and K. TanAnvik, S. Bromling and K. Tan

StudentStudent : : Chih-Kun ChangChih-Kun Chang

AdvisorAdvisor : : Ku-Yaw ChangKu-Yaw Chang

Page 2: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 2

Outline

Introduction Design pattern adaptation Constructing generative patterns Generative pattern representation Summary

Page 3: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 3

Introduction

Generative Design Pattern 介紹 Composite Pattern 介紹 CO2P2S 簡介及實作

Page 4: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 4

Question 1. Why design patterns are not used as generative constructs that support code re-use ?

Ans. 1. It is difficult to generate a single body of code that adequately solves each problem in the family. 2. It is difficult to construct and edit generative design patterns. 3. Lack of a tool-independent representation

CO2P2S (Correct Object-Oriented Pattern-based Programming System ) Meta-CO2P2S

Page 5: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 5

Question 2. It would be beneficial to use generative design

patterns that generative code , why ? 1. They reduce implementation time , are less prone

to programmer error.2. Promote rapid prototyping and code reuse.3. Support performance tuning.4. Provide better overall software engineering

benefits.

Page 6: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 6

Introduction

Generative design pattern problems Parameterized design patterns

Page 7: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 7

Introduction

Generative design pattern problems When to code generation

before adaptation (AOP)

during adaptation (better)

after adaptation (Framework)

AOP – Aspect-Oriented Programming

Page 8: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 8

Introduction

before adaptationIt is very difficult to generate code before

adaptation that is general for all of the problems the pattern is designed to solve.

If this problem could be solved , the code would often be too complex and often too generic to achieve good performance.

Page 9: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 9

Introduction

after adaptation The pattern quickly gathers application-specific characteristics

The generated code is only applicable to applications similar to our graphics application.

Page 10: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 10

Introduction

during adaptation an arbitrary number of adaptation and an arbitrary number of adaptation and

code generation cycles.code generation cycles. Simplest process that provides Simplest process that provides usable usable

resultsresults..• The initial adaptation phase• The code generation phase• The final adaptation phase

Page 11: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 11

Introduction

Parameterized design patternsPublished descriptive design patterns

include : 1. lists of participants ( 關係者 ) 2. implementation issues ( 成就發佈 ) 3. sample code.

However, they are not sufficient for generative design patterns.

Page 12: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 12

Introduction

Parameterized design patternsEach descriptive design pattern is

transformed into a generative design pattern using quantitative parameters with specific domains.

The parameters can be classified into a few distinct types.

Page 13: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 13

Introduction

The complete process takes three steps. Step1. the user selects an appropriate

generative design pattern from a set of supported patterns.

Step2. the user adapts this pattern for their application by providing parameter values.

Step3. the adapted generative pattern is used to create object-oriented framework code for the chosen pattern structure.

Page 14: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 14

Introduction

Patterns to frameworks to applications.

The specialization flow, from generative design pattern to finalapplication code.

Page 15: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 15

Outline

Introduction Design pattern adaptation Constructing generative patterns Generative pattern representation Summary

Page 16: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 16

Composite pattern Composite pattern. “Compose objects

into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

將對象組合成樹狀結構以表示“部分 -整體”的層次結構。 Composite模式使得使用者對單個對象和组合對象的使用具一致性。

Page 17: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 17

The Composite design pattern

Perhaps the leaf classes are Line and Circle the composite classes are Group (an arbitrary collection of other components) and Quadrilateral the composite classes are Group (an arbitrary collection of other components) and Quadrilateral

(a specific collection of four lines)(a specific collection of four lines)

Page 18: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 18

The Composite design pattern

算術式算術式包括數字、操作符號和另一個數字。操作數可以是數字,也可以是包括數字、操作符號和另一個數字。操作數可以是數字,也可以是

另一個表述式。例如,另一個表述式。例如, 2+3 2+3 和(和( 2+32+3 )) ++ (( 4*64*6 )都是合法的表述式。)都是合法的表述式。

Page 19: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 19

Design pattern adaptation

Parameters for the Composite patternParameters for the Composite pattern Tool support for setting parametersTool support for setting parameters

Page 20: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 20

Design pattern adaptation

The Composite design pattern has seven parameters

1.(lexical) component name. 1.(lexical) component name. The name for the abstract component class.The name for the abstract component class.

2.(lexical) composite name. 2.(lexical) composite name. TheThe name for the abstract composit class.name for the abstract composit class.

3.(lexical) leaf name. 3.(lexical) leaf name. The name for the abstract leaf class in the generated framework.The name for the abstract leaf class in the generated framework.

4.(lexical) superclass name. 4.(lexical) superclass name. A name for the pattern superclass.A name for the pattern superclass.

5.(design) safe-transparent. 5.(design) safe-transparent. The location of the child management operations.The location of the child management operations.

6.(design) operation list. 6.(design) operation list. A traversal list.A traversal list.

7.(performance) containers. 7.(performance) containers. The types of containers used.The types of containers used.

Page 21: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 21

Design pattern adaptation

seven parameters component name , composite name , leaf component name , composite name , leaf

name name user controlsuser controls Superclass name Superclass name java java If no superclass is required , the If no superclass is required , the user can enteruser can enter ObjectObject.. C++ C++ target language , an target language , an empty empty superclass namesuperclass name could be used. could be used.

Page 22: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 22

Design pattern adaptation

seven parameters -- safe-transparentHas parameter type Enumeration. two value : safe and transparent.

If the safe value is selected , the child management operations are generated in the composite class.

If the transparent value is selected , the child management operations are generated in the component class.

Page 23: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 23

Design pattern adaptation

seven parameters – operation-list Has parameter type List - a List parameter is a

list of parameters of arbitrary type. Has type Structure – has three sub-parameters.

Operation signature – has type Method Signature. Example draw( ).

Prefix – 先畫背景再畫前景 Suffix – include all of the parameters

of the operation method that calls it .

Page 24: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 24

Design pattern adaptation seven parameters – containers

The containers parameter is the only performance parameter of the Composite pattern. Has type Dictionary. It supports an arbitrary number of abstract composite classes, with different names and implementations. Each key in this Dictionary is an Enumeration value from :

{ vector , array, list , hash table, two children, three children, four children }

Ex. ListComposit to support Group and FourComposite to support Quadrilateral

Page 25: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 25

Design pattern adaptation

Parameters for the Composite patternParameters for the Composite pattern Tool support for setting parametersTool support for setting parameters

Page 26: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 26

Tool support for setting parameters

Page 27: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 27

Tool support for setting parameters

CO2P3S (Correct Object-Oriented Pattern-based Parallel Programming System)

combines design patterns and object-oriented frameworks into a process for writing high-performance object-oriented programs that execute on multiple processors

Page 28: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 28

Tool support for setting parameters

Operating systems: Linux Solaris SGI Irix

Other System Requirements A Java distribution, Version 1.2 or higher. A Perl distribution, Version 5 or higher Any version of GNU make An active network connection.

Page 29: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 29

Outline

Introduction Design pattern adaptation Constructing generative patterns Generative pattern representation Summary

Page 30: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 30

Constructing generative patterns

Generative pattern parameter types Framework generation Using Javadoc for code generation Tool support Meta-CO2P2S

Page 31: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 31

Generative pattern parameter types

Generative pattern parameters allow a pattern designer to customize a pattern and alter the framework code that it generates.

There are three basic parameter types. String – simple legal string value

Enumeration – fixed set of values

List – handles the common situation where the pattern user supplies a list of other parameters, which may be of any type.

Page 32: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 32

The specialization hierarchy for parameter types.

Generative pattern parameter types

Page 33: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 33

Generative pattern parameter types IdentifierIdentifier – – has a value that is any legal identifier in the target has a value that is any legal identifier in the target

programming language.programming language. Class NameClass Name – is included in each generative pattern. – is included in each generative pattern. Method NameMethod Name – represents the name of a method. – represents the name of a method. BooleanBoolean – is a special case of Enumeration, where the legal values – is a special case of Enumeration, where the legal values

are true and false.are true and false. StructureStructure – deals with the common case where a parameter – deals with the common case where a parameter

consists of a fixed number of sub-parameters.consists of a fixed number of sub-parameters. Method SignatureMethod Signature – specifies the name , return type and – specifies the name , return type and

argument types of a method.argument types of a method. DictionaryDictionary – maps keys to values for the code generator. This is – maps keys to values for the code generator. This is

particularly useful for multiple selection parameters.particularly useful for multiple selection parameters. ExtendedExtended – supports the case where the parameter values have an – supports the case where the parameter values have an

arbitrary form. Such as a way for the pattern user to supply the arbitrary form. Such as a way for the pattern user to supply the parameter value and how different values affect the generated code.parameter value and how different values affect the generated code.

Page 34: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 34

Constructing generative patterns

Generative pattern parameter types Framework generation Using Javadoc for code generation Tool support Meta-CO2P2S

Page 35: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 35

Framework generation

String parameter is represented by a String Placeholder in the source code template.

Enumeration parameter is represented by a Guard Variable that can be assigned one value from the domain of the Enumeration parameter.

Page 36: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 36

Framework generation

List parameter is represented in the code by a List Placeholder that indicates its location.

Extend parameter has no fixed transformation technique for code generation. An Extended Placeholder marks its location in the code template.

Page 37: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 37

Constructing generative patterns

Generative pattern parameter types Framework generation Using Javadoc for code generation Tool support Meta-CO2P2S

Page 38: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 38

Using Javadoc for code generation

Javadoc is a tool whose original purpose was to generate HTML formatted API documentation for Java classes.

Page 39: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 39

Constructing generative patterns

Generative pattern parameter types Framework generation Using Javadoc for code generation Tool support Meta-CO2P2S

Page 40: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 40

Tool support Meta-CO2P2S

Meta-CO2P2S bundles the parameter information and GUI attributes together and stores the information in a file with standard XML format .

Page 41: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 41

Outline

Introduction Design pattern adaptation Constructing generative patterns Generative pattern representation Summary

Page 42: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 42

Generative pattern representation

Pattern parameter representation Uses XML format

Automating parameter value entry A String parameter can be entered in a standard

dialog box with a single text field. An Enumeration parameter is entered by a set of

labels or graphical images and associated radio buttons.

A List parameter uses a list pane , and buttons for adding and removing elements.

Page 43: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 43

Generative pattern representation

Framework representationCode generator is based on Javadoc.It is possible to create a library of these

reusable behavioral components to support parameter sharing between patterns.

Page 44: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 44

Outline

Introduction Design pattern adaptation Constructing generative patterns Generative pattern representation Summary

Page 45: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 45

Summary Three new ideas:

Generative design patterns are defined by a set of typed parameters with specific legal values and a code template that generates frameworks whose structure depends on combinations of values for these parameters

Design pattern adaptation is a three-phase process Design pattern adaptation is a three-phase process First phaseFirst phase involves parameter value selection involves parameter value selection Second phaseSecond phase involves framework code generation involves framework code generation Third phaseThird phase involves framework specialization. involves framework specialization.

A two part tool-independent representation of generative A two part tool-independent representation of generative design patterns consists of an design patterns consists of an XML-basedXML-based representation of representation of pattern parameter values and a code template with simple pattern parameter values and a code template with simple parameter-based annotations.parameter-based annotations.

Page 46: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 46

Summary

CO2P2S currently supports Six design patterns for parallel computing:

mesh, wavefront, pipeline, search-tree, distributor and phases.

Sequential patterns: composite, decorator, abstract factory, chain (tree) of responsibility and observer.

Page 47: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 47

Summary

Generative design pattern to write an application, follows four steps: ( ( programmer programmer ) ) PickPick an appropriate set of design patterns. an appropriate set of design patterns. Use a tool like CO2P2S to adapt design patterns to

an application by selecting values for the pattern parameters.

Press a button to generate frameworks for each design pattern that has been customized for your application.

Use framework specialization to finish the application.

Page 48: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 48

Summary To create a new generative design pattern ,

follows four steps: ( ( designer ) ) Find an existing descriptive design pattern that applies

or create a new descriptive design pattern. Study existing generative design patterns for similar

issues and parameterization requirements. determine the legal parameter values by considering the

necessary parameter values for your application and the known uses section of the pattern documentation

Use other generative design patterns to guide you, or if possible, edit an existing generative design pattern to take advantage of the code template that has already been written.

Page 49: Generative Design Pattern Source : 17th IEEE International Conference on Automated Software Engineering, Automated Software Engineering, Edinburgh, U.K.,

Chin-Kun Chang Generative Design Pattern 49

Thank you!