The Ptidej Tool Suite aims to analyze object-oriented programs to detect patterns at the code, design, and architecture levels in order to improve software quality, utilizing the Pattern and Abstract-level Description Language (PADL) meta-model to represent patterns and program structures for analysis by various PADL tools.
The Codex of Business Writing Software for Real-World Solutions 2.pptx
Ptidej Tool Suite: Software Patterns
1. Ptidej Tool Suite
Yann-Gaël Guéhéneuc
yann-gael.gueheneuc@polytmtl.ca
Presentation in Sukyoung Ruy’s group
KAIST
2013/06/07
Département de génie informatique et de génie logiciel
This work is licensed under a Creative
Commons Attribution-NonCommercialShareAlike 3.0 Unported License
9. Patterns
“[E]xisting books on design patterns take a
catalog approach, where they show the
individual design patterns in isolation. This
approach is […] flawed, because you can't see
how the design patterns actually function in the
real world. Most programmers learn by looking
at computer programs.”
—Allen Holub in Holub on Patterns: Learning
Design Patterns by Looking at Code
9/69
13. Patterns
Several books, articles
– Amazon.com
• Exclusion
– Unreleased books
– Specific to a technology or frameworks
» e.g., MVVM Unleashed by Michael Brown
– Process oriented, user-interface, programming languages
» e.g., Process Patterns: Building Large-Scale Systems
Using Object Technology by Scott W. Ambler and
Barbara Hanscome
– Proceedings of conferences
– Unrelated to software engineering
13/69
14. Patterns
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
Pattern-Oriented Software Architecture, Patterns for Concurrent and Networked Objects: Volume 2 (Wiley Software...
by Douglas C. Schmidt, Michael Stal, Hans Rohnert and Frank Buschmann
Pattern-Oriented Software Architecture, Patterns for Resource Management: Volume 3 (Wiley Software Patterns
Series... by Michael Kircher and Prashant Jain
Pattern-Oriented Software Architecture, A System of Patterns: Volume 1 (Wiley Software Patterns Series) by Frank
Buschmann, Regine Meunier, Hans Rohnert and Peter Sommerlad
Pattern-Oriented Software Architecture For Dummies (For Dummies (Computers)) by Robert Hanmer
Web Security Patterns by Ramesh Nagappan and Christopher Steel
Safe C++ by Vladimir Kushnir
Programming in the Large with Design Patterns by Eddie Burris
Elemental Design Patterns by Jason McC. Smith
Java Application Architecture: Modularity Patterns with Examples Using OSGi (Robert C. Martin Series) by Kirk
Knoernschild
Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions (Addison-Wesley
Signature... by Gregor Hohpe and Bobby Woolf
Patterns of Enterprise Application Architecture (Addison-Wesley Signature Series (Fowler)) by Martin Fowler
Cognitive Patterns: Problem-Solving Frameworks for Object Technology by Robert K Konitzer, Bobbin Teegarden,
Alexander Rush and Karen M Gardner
Service Design Patterns: Fundamental Design Solutions for SOAP/WSDL and RESTful Web Services by Robert
Daigneau
The ACE Programmer's Guide: Practical Design Patterns for Network and Systems Programming by Stephen D.
Huston, James CE Johnson and Umar Syyid
Patterns for Parallel Software Design (Wiley Software Patterns Series) by Jorge Luis Ortega-Arjona
Design Patterns in Object-oriented ABAP by Igor Barbaric
Object-Oriented Reengineering Patterns by Oscar Nierstrasz, Stéphane Ducasse and Serge Demeyer
Dependency Injection by Dhanji R. Prasanna
Object-Oriented Software Engineering Using UML, Patterns, and Java (3rd Edition) by Bernd Bruegge and Allen H.
Dutoit
J2EE Design Patterns by William Crawford and Jonathan Kaplan
Applying UML and Patterns: An Introduction to Object-oriented Analysis and Design and Iterative Development by
Craig Larman
Object-oriented Analysis and Design Using Umlan Introduction to Unified Process and Design Patterns by Mahesh P.
Matha
C++ Design Patterns and Derivatives Pricing (Mathematics, Finance and Risk) by M. S. Joshi
Effective Java (2nd Edition) by Joshua Bloch
Patterns for Fault Tolerant Software (Wiley Software Patterns Series) by Robert Hanmer
Implementation Patterns by Kent Beck
Patterns for Computer-Mediated Interaction (Wiley Software Patterns Series) by Till Schummer and Stephan Lukosch
Pattern Oriented Software Architecture Volume 5: On Patterns and Pattern Languages by Frank Buschmann, Kevlin
Henney and Douglas C. Schmidt
Object-Oriented Analysis and Design with Applications (3rd Edition) by Grady Booch, Robert A. Maksimchuk, Michael
W. Engle and Bobbi J. Young
Head First Object-Oriented Analysis and Design by Brett D. McLaughlin, Gary Pollice and Dave West
Agile Principles, Patterns, and Practices in C# by Robert C. Martin and Micah Martin
Design Patterns For Dummies by Steve Holzner
Pattern Languages of Program Design 5 by Dragos Manolescu, Markus Voelter and James Noble
Design Patterns in Java(TM) (Software Patterns Series) by Steven John Metsker and William C. Wake
Object-Oriented Design and Patterns by Cay S. Horstmann
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
Object-Oriented Modeling and Design with UML (2nd Edition) by Michael R. Blaha and James R Rumbaugh
Remoting Patterns: Foundations of Enterprise, Internet and Realtime Distributed Object Middleware (Wiley
Software... by Markus Völter, Michael Kircher and Uwe Zdun
Software Factories: Assembling Applications with Patterns, Models, Frameworks, and Tools (Wiley Application
Development... by Jack Greenfield, Keith Short, Steve Cook and Stuart Kent
Refactoring to Patterns by Joshua Kerievsky
Architecting Enterprise Solutions: Patterns for High-Capability Internet-based Systems (Wiley Software Patterns...
by Paul Dyson and Andrew Longshaw
Enterprise Patterns and MDA: Building Better Software with Archetype Patterns and UML by Jim Arlow and Ila
Neustadt
Data Access Patterns: Database Interactions in Object-Oriented Applications by Clifton Nock
Domain-Driven Design: Tackling Complexity in the Heart of Software by Eric Evans
Pattern-Oriented Analysis and Design: Composing Patterns to Design Software Systems by Sherif M. Yacoub,
Hany H. Ammar, Sherif Yacoub and Hany Ammar
Java Extreme Programming Cookbook by Eric M. Burke and Brian M. Coyner
J2EE Best Practices: Java Design Patterns, Automation, and Performance (Wiley Application Development
Series) by Darren Broemmer
Real-Time Design Patterns: Robust Scalable Architecture for Real-Time Systems by Bruce Powel Douglass
Design Patterns Java¿ Workbook by Steven John Metsker
EJB Design Patterns: Advanced Patterns, Processes, and Idioms by Floyd Marinescu
Streamlined Object Modeling: Patterns, Rules, and Implementation by Jill Nicola, Mark Mayfield and Mike Abney
Design Patterns Explained: A New Perspective on Object-Oriented Design by Alan Shalloway and James Trott
Small Memory Software: Patterns for systems with limited memory (Software Patterns Series) by James Noble
and Charles Weir
AntiPatterns in Project Management by William J. Brown, Hays W. "Skip" McCormick III and Scott W. Thomas
Pattern Languages of Program Design 4 (Software Patterns Series) by Brian Foote, Neil Harrison and Hans
Rohnert
Testing Object-Oriented Systems: Models, Patterns, and Tools by Robert V. Binder
Design Patterns and Contracts by Jean-Marc Jezequel, Michel Train and Christine Mingins
Object-Oriented Software Development Using Java: Principles, Patterns, and Frameworks (1/e) by Xiaoping Jia
Refactoring: Improving the Design of Existing Code by Martin Fowler, Kent Beck, John Brant and William Opdyke
More Process Patterns: Delivering Large-Scale Systems Using Object Technology (SIGS: Managing Object
Technology... by Scott W. Ambler
Pattern Hatching: Design Patterns Applied by John Vlissides
AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J. Brown, Raphael C. Malveau,
Hays W. "Skip" McCormick and Thomas J. Mowbray
A Little Java, A Few Patterns (Language, Speech, & Communication) by Matthias Felleisen, Daniel P. Friedman
and Ralph E. Johnson
Pattern Languages of Program Design 3 (v. 3) by Robert C. Martin, Dirk Riehle and Frank Buschmann
Object Models: Strategies, Patterns, and Applications (2nd Edition) by Peter Coad, David North and Mark Mayfield
Analysis Patterns: Reusable Object Models by Martin Fowler
Patterns of Software: Tales from the Software Community by Richard P. Gabriel
Pattern Languages of Program Design 2 (v. 2) by John Vlissides, James O. Coplien and Norman L. Kerth
Software Patterns by James Coplien
Software Architecture: Perspectives on an Emerging Discipline by Mary Shaw and David Garlan
Adaptive Object-Oriented Software: The Demeter Method with Propagation Patterns: The Demeter Method with
Propagation... by Karl Lieberherr
Pattern Languages of Program Design by James O. Coplien and Douglas C. Schmidt
14/69
15. Patterns
The following is not a substitute to reading
previous books and practicing
The following is complementary to reading
books and practicing
– These patterns that have been “found” the hard
way and that work (or do not work!)
15/69
16. Patterns
The following is not a substitute to reading
these books and practicing
The following is complementary to reading
books and practicing
– These patterns that have been “found” the hard
way and that work (or do not work!)
16/69
17. Patterns
General form as for the GoF , also inspired
by Coplien’s form
– Name
– Problem(s)
– Solution
– Consequences
17/69
18. Patterns
General form as for the GoF, also inspired
by Coplien’s form
– Name
– Problem(s)
– Example(s)
– Solution
– Example(s)
– Consequences
– (Follow-up)
18/69
19. Patterns
General form as for the GoF, also inspired
by Coplien’s form
– Name
– Problem(s)
– Example(s)
– Solution
– Example(s)
– Consequences
– (Follow-up)
Problem:
Solution:
19/69
20. Patterns
General form as for the GoF, also inspired
by Coplien’s form
– Not formal
– Room for interpretation
– But…
• UML-like class diagrams
• UML-like sequence diagrams
• Smalltalk / C++ example code
20/69
22. Ptidej Tool Suite
Context
– Research work started since my Ph.D. thesis
(2000–2003)
– Pattern Trace Identification, Detection, and
Enhancement in Java
• Theories, methods, and tools, to evaluate and to
improve the quality of object-oriented programs by
promoting the use of idioms, design patterns, and
architectural patterns
22/69
23. Ptidej Tool Suite
Requirements
– Software tools
• Support the analysis of the implementation, design,
and architecture of object-oriented programs
• Support the detection and introduction of patterns at
the code, design, and architectural levels
23/69
24. Ptidej Tool Suite
Analysis
– Domain concepts
• “quality of object-oriented”
• “promoting the use of idioms, design patterns, and
architectural patterns”
• “analysis of the implementation, design, and
architecture of object-oriented programs”
• “detection and introduction of patterns at the code,
design, and architectural levels”
24/69
25. Ptidej Tool Suite
Analysis
– Domain concepts
• “quality of object-oriented”
• “promoting the use of idioms, design patterns, and
architectural patterns”
• “analysis of the implementation, design, and
architecture of object-oriented programs”
• “detection and introduction of patterns at the code,
design, and architectural levels”
25/69
26. Ptidej Tool Suite
Constraint
– Apply patterns/best practices (existing or new)
when developing the tools
• Architectural
• Design
• Implementation
– Self-imposed but sensible
• “Eating your own dog food”
(http://www.urbandictionary.com/define.php?
term=eating%20your%20own%20dog%20food)
26/69
27. Ptidej Tool Suite
Related work
– Various parsers (target languages)
e.g., GCCXML
– Various meta-model (sometimes implicit)
•
•
•
•
Similar to UML meta-model (1997)
Before OMG KDM (2003)
Before Eclipse EMF (2004)
Before OMG MOF (2006)
– Various tools
e.g., Rigi (H. M. Kienle and H. A. Müller: Rigi – An environment
for software reverse engineering, exploration, visualization, and
redocumentation. Sci. Comput. Program. 75(4): 247-263, 2010)
27/69
28. Ptidej Tool Suite
Related work
↑ Existing ☺
↓ Too low-level
e.g., GCCXML
↓ No “free” parsers
e.g., UML meta-model
↓ Difficult to access / to use / to adapt
e.g., Rigi
28/69
29. Ptidej Tool Suite
Related work
– Pierre Cointe’s team in 2000 at École des Mines
de Nantes, France
– Fertile ground
• Hervé Albin-Amiot was already developing a metamodel to describe design patterns
– “Idioms and patterns Java: application to code synthesis and
detection” (Ph.D. in 2003)
– PDL (Pattern Description Language)
29/69
53. Ptidej Tool Suite
Advantages
– Available! ☺
• https://web.soccerlab.polymtl.ca/rptidej/ptidejlab/
Software/Ptidej 5 Workspace
• Username: guestsvn
• Password: g1u2e3s4t5
– See also
• http://www.ptidej.net/material/inanutshell
• http://www.ptidej.net/material/development/
• http://wiki.ptidej.net/doku.php
53/69
54. Ptidej Tool Suite
Advantages
– Extensible
e.g., C++ creator provide new/modified constituent
• Factory design pattern
• Builder design pattern
– Including for the user interface
54/69
55. Ptidej Tool Suite
Limits
– Coarse representation
of method statements
– Unsatisfactory support of non-typed, non-objectoriented programming languages
• (Very) partial support for Smalltalk
55/69
57. Ptidej Tool Suite
Academic Usage
– Dozen of empirical studies
e.g., S. Kpodjedo, F. Ricca, P. Galinier, G. Antoniol,
and Y.-G. Guéhéneuc. MADMatch: Many-to-many
Approximate Diagram Matching for Design
Comparison. IEEE TSE, Feburary 2013
– Please see
• http://www.ptidej.net/publications/
57/69
58. Ptidej Tool Suite
Concrete Usage
– Build a model from some C++ code (1/2)
public static IIdiomLevelModel generateModelFromCppFilesUsingEclipse(
final String aName,
final String aSourceDirectory,
final IModelListener aModelListener) {
ICodeLevelModel codeLevelModel = null;
try {
final ICodeLevelModelCreator creator =
new padl.creator.cppfile.eclipse.CppCreator(aSourceDirectory);
codeLevelModel =
CPPFactoryEclipse.getInstance().createCodeLevelModel(aName);
if (aModelListener != null) {
codeLevelModel.addModelListener(aModelListener);
}
codeLevelModel.create(creator);
}
catch (final CreationException e) {
e.printStackTrace(ProxyConsole.getInstance().errorOutput());
}
...
58/69
59. Specialised creator
Ptidej Tool Suite
Concrete Usage
– Build a model from some C++ code (1/2)
public static IIdiomLevelModel generateModelFromCppFilesUsingEclipse(
final String aName,
final String aSourceDirectory,
final IModelListener aModelListener) {
ICodeLevelModel codeLevelModel = null;
try {
final ICodeLevelModelCreator creator =
new padl.creator.cppfile.eclipse.CppCreator(aSourceDirectory);
codeLevelModel =
CPPFactoryEclipse.getInstance().createCodeLevelModel(aName);
if (aModelListener != null) {
codeLevelModel.addModelListener(aModelListener);
}
codeLevelModel.create(creator);
}
catch (final CreationException e) {
e.printStackTrace(ProxyConsole.getInstance().errorOutput());
}
...
59/69
60. Specialised creator
Ptidej Tool Suite
Concrete Usage
Specialised factory to
allow new constituents
– Build a model from some C++ code (1/2)
public static IIdiomLevelModel generateModelFromCppFilesUsingEclipse(
final String aName,
final String aSourceDirectory,
final IModelListener aModelListener) {
ICodeLevelModel codeLevelModel = null;
try {
final ICodeLevelModelCreator creator =
new padl.creator.cppfile.eclipse.CppCreator(aSourceDirectory);
codeLevelModel =
CPPFactoryEclipse.getInstance().createCodeLevelModel(aName);
if (aModelListener != null) {
codeLevelModel.addModelListener(aModelListener);
}
codeLevelModel.create(creator);
}
catch (final CreationException e) {
e.printStackTrace(ProxyConsole.getInstance().errorOutput());
}
...
60/69
61. Specialised creator
Ptidej Tool Suite
Concrete Usage
Specialised factory to
allow new constituents
Builder design pattern
– Build a model from some C++ code (1/2)
public static IIdiomLevelModel generateModelFromCppFilesUsingEclipse(
final String aName,
final String aSourceDirectory,
final IModelListener aModelListener) {
ICodeLevelModel codeLevelModel = null;
try {
final ICodeLevelModelCreator creator =
new padl.creator.cppfile.eclipse.CppCreator(aSourceDirectory);
codeLevelModel =
CPPFactoryEclipse.getInstance().createCodeLevelModel(aName);
if (aModelListener != null) {
codeLevelModel.addModelListener(aModelListener);
}
codeLevelModel.create(creator);
}
catch (final CreationException e) {
e.printStackTrace(ProxyConsole.getInstance().errorOutput());
}
...
61/69
62. Ptidej Tool Suite
Concrete Usage
– Build a model from some C++ code (2/2)
public static IIdiomLevelModel generateModelFromCppFilesUsingEclipse(
final String aName,
final String aSourceDirectory,
final IModelListener aModelListener) {
...
IIdiomLevelModel idiomLevelModel = null;
try {
idiomLevelModel =
(IIdiomLevelModel) new AACRelationshipsAnalysis().invoke(aCodeLevelModel);
}
catch (final UnsupportedSourceModelException e) {
e.printStackTrace(ProxyConsole.getInstance().errorOutput());
}
return idiomLevelModel;
}
62/69
63. Promotion of the model
Ptidej Tool Suite
Concrete Usage
– Build a model from some C++ code (2/2)
public static IIdiomLevelModel generateModelFromCppFilesUsingEclipse(
final String aName,
final String aSourceDirectory,
final IModelListener aModelListener) {
...
IIdiomLevelModel idiomLevelModel = null;
try {
idiomLevelModel =
(IIdiomLevelModel) new AACRelationshipsAnalysis().invoke(aCodeLevelModel);
}
catch (final UnsupportedSourceModelException e) {
e.printStackTrace(ProxyConsole.getInstance().errorOutput());
}
return idiomLevelModel;
}
63/69
64. Ptidej Tool Suite
Concrete Usage
– Identify occurrence of the Composite DM
final Problem problem =
CompositeMotif.getProblem(Manager.build(idiomLevelModel));
final StringWriter writer = new StringWriter();
problem.setWriter(new PrintWriter(writer));
problem.automaticSolve(true);
final Properties properties = new Properties();
properties.load(new ReaderInputStream(new StringReader(writer.getBuffer().toString())));
final OccurrenceBuilder solutionBuilder = OccurrenceBuilder.getInstance();
final Occurrence[] solutions = solutionBuilder.getCanonicalOccurrences(properties);
64/69
65. Ptidej Tool Suite
From a library of
design motifs
Concrete Usage
– Identify occurrence of the Composite DM
final Problem problem =
CompositeMotif.getProblem(Manager.build(idiomLevelModel));
final StringWriter writer = new StringWriter();
problem.setWriter(new PrintWriter(writer));
problem.automaticSolve(true);
final Properties properties = new Properties();
properties.load(new ReaderInputStream(new StringReader(writer.getBuffer().toString())));
final OccurrenceBuilder solutionBuilder = OccurrenceBuilder.getInstance();
final Occurrence[] solutions = solutionBuilder.getCanonicalOccurrences(properties);
65/69
66. Ptidej Tool Suite
Concrete Usage
– Identify occurrence of the Blob anti-pattern
final IDesignSmellDetection detection = (IDesignSmellDetection) new BlobDetection();
detection.setMetricsFileRepository(ClassFileRepository.getInstance(Repository.class));
detection.setModel(idiomLevelModel);
detection.performDetection();
final String path = ...;
detection.output(new PrintWriter(ProxyDisk.getInstance().fileTempOutput(path)));
final Properties properties = new Properties();
properties.load(new ReaderInputStream(ProxyDisk.getInstance().fileTempInput(path)));
final OccurrenceBuilder solutionBuilder = OccurrenceBuilder.getInstance();
final Occurrence[] solutions = solutionBuilder.getCanonicalOccurrences(properties);
66/69
67. Ptidej Tool Suite
From a library of
anti-patterns
Concrete Usage
– Identify occurrence of the Blob anti-pattern
final IDesignSmellDetection detection = (IDesignSmellDetection) new BlobDetection();
detection.setMetricsFileRepository(ClassFileRepository.getInstance(Repository.class));
detection.setModel(idiomLevelModel);
detection.performDetection();
final String path = ...;
detection.output(new PrintWriter(ProxyDisk.getInstance().fileTempOutput(path)));
final Properties properties = new Properties();
properties.load(new ReaderInputStream(ProxyDisk.getInstance().fileTempInput(path)));
final OccurrenceBuilder solutionBuilder = OccurrenceBuilder.getInstance();
final Occurrence[] solutions = solutionBuilder.getCanonicalOccurrences(properties);
67/69
68. Ptidej Tool Suite
Limitations and future work
– Treatment and modelling of method bodies
• Coarse grain multi-language support for method
bodies currently available
• Fine grain through meta-model extension
– Treatment and modelling of non-typed, nonobject-oriented programming languages
• Unsatisfactory support for Smalltalk
• No support for PHP, JavaScript
68/69
69. Ptidej Tool Suite
Limitations and future work
– Treatment and modelling of method bodies
• Coarse grain multi-language support for method
bodies currently available
• Fine grain through meta-model extension
– Treatment and modelling of non-typed, nonobject-oriented programming languages
• Unsatisfactory support for Smalltalk
• No support for PHP, JavaScript
69/69