Detecting Patterns and Antipatterns in Software using Prolog Rules Alecsandar Stoianov, Ioana Sora Department of Computers Politehnica University of Timisoara,

Slides:



Advertisements
Similar presentations
Alecsandar STOIANOV. Legacy software Introduction.
Advertisements

Design Patterns for Object Oriented systems CSC 515 Ashwin Dandwate.
Design Patterns Yes, they are important Robert Cotton April 23, 2009.
05/26/2004www.indyjug.net1 Indy Java User’s Group June Knowledge Services, Inc.
(c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.
Architecture Eclipse Framework with Plugin Concept JTransformer Plugin Analysis + Transformation interface: logical Program.language keeps representation.
Design Patterns CS is not simply about programming
Ralph Johnson - University of Illinois1 Patterns: What They Are, and How to Write Them Ralph Johnson University of Illinois at Urbana-Champaign
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Automatically Extracting and Verifying Design Patterns in Java Code James Norris Ruchika Agrawal Computer Science Department Stanford University {jcn,
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Adapters Presented By Zachary Dea. Definition A pattern found in class diagrams in which you are able to reuse an ‘adaptee’ class by providing a class,
13-Jul-15 Refactoring II. Books Design Patterns is the classic book by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides Basically a catalog.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Design Patterns Trends and Case Study John Hurst June 2005.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 1, Introduction to Software Engineering.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
Implementing Design Patterns Using Java St. Louis Java Special Interest Group Eric M. Burke Object Computing, Inc. Presented on July 9, 1998 (updated July.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Aniruddha Chakrabarti
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
Programming in Java Unit 3. Learning outcome:  LO2:Be able to design Java solutions  LO3:Be able to implement Java solutions Assessment criteria: 
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
Mastergoal Machine Learning Environment Phase III Presentation Alejandro Alliana CIS895 MSE Project – KSU.
Design Patterns Introduction What is a Design Pattern? Why were they developed? Why should we use them? How important are they?
DESIGN PATTERNS CSC532 Adv. Topics in Software Engineering Shirin A. Lakhani.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Patterns and AntiPatterns Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
05/26/2004www.indyjug.net1 Indy Java User’s Group May Knowledge Services, Inc.
CS 160: Software Engineering October 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Architectural Styles, Design Patterns, and Objects Joe Paulowskey.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
An Introduction To Design Patterns Jean-Paul S. Boodhoo Independent Consultant
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
CS251 – Software Engineering Lectures 18: Intro to DP Slides by Rick Mercer, Christian Ratliff, Oscar Nierstrasz and others 1 و ابتغ فيما آتاك الله الدار.
Patterns Composite Pattern. Patterns All designers use patterns. Patterns in solutions come from patterns in problems. "A pattern is a solution to a problem.
Design Patterns in Context ©SoftMoore ConsultingSlide 1.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
A proposal to support the extreme programming development methodology from the quality assurance point of view Authors: Calin Jebelean –
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Design and implementation Chapter 7 – Lecture 1. Design and implementation Software design and implementation is the stage in the software engineering.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Software Design Refinement Using Design Patterns
The Object-Oriented Thought Process Chapter 15
Chapter 5:Design Patterns
MPCS – Advanced java Programming
Pertemuan 08 Design Patterns & Anti-Patterns
Introduction to Design Patterns
Design Patterns Introduction
Unified Modeling Language
Design Patterns.
Presented by Igor Ivković
Refactoring II 21-Sep-18.
DESIGNING YOUR SYSTEM.
Refactoring II 5-Feb-19.
DESIGN PATTERNS : Introduction
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Informatics 122 Software Design II
Composite Design Pattern By Aravind Reddy Patlola.
Presented by Igor Ivković
CIS 644  Object-Oriented Design and Development. (3) 
Presentation transcript:

Detecting Patterns and Antipatterns in Software using Prolog Rules Alecsandar Stoianov, Ioana Sora Department of Computers Politehnica University of Timisoara, Romania

Design Patterns and Antipatterns Design pattern: “describes a commonly-recurring structure of communicating components that solves a general design problem within a particular contex” AntiPatterns: “like their design pattern counterparts, describe common mistakes occuring in software projects “ Catalogues of patterns and antipatterns: [Go4] Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides: Design Patterns: Elements of Reusable Object-Oriented Software [POSA] Frank Buschmann et al.: Pattern Oriented Software Architecture [Brown] William J. Brown, Raphael C. Malveau, Hays W. McCormick III, Thomas J. Mowbray: AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis [Fowler] M. Fowler, Refactoring: Improving the Design of Existing Code. [Lanza&Marinescu] Michele Lanza, Radu Marinescu: Object-Oriented Metrics in Practice

“Talking in patterns” Example: “The system has a clear client-server structure, but the MySpecialProcesser server is spaghetti-code” Benefits: Patterns and AntiPatterns define a higher-level vocabulary : it simplifies communication between software practitioners enables concise description of abstract concepts. Knowing about the presence of Patterns or AntiPatterns helps program comprehension Problem: lack of documentation in many cases the usage of patterns is seldom documented, while antipatterns are never described as such in the product documentation. Solution: automatic or semiautomatic tools for discovering both Patterns and AntiPatterns from source code can help program comprehension

State of the Art and Objectives State of the art: Different tools address specific issues – usually each tools is based on one catalog Different approaches – most do static analysis, few dynamic analysis, some metric-based Tool examples: Pinot – design pattern detection => [Go4] pattern catalogue Decor – detection of code and design smells => [Brown] IPlasma – detection of design flaws => [Lanza&Marinescu] Our objectives: tool for program comprehension – “one tool for all” easy definition of both patterns and antipatterns possibility to define patterns and antipatterns by both structural connections among classes and also by specific sequences of actions and interactions of the objects

Our approach Prerequisites: The program to be analysed must be available as Java sourcecode) we use Jtransformer to obtain a complete AST representation in form of Prolog clauses Our analysis tool: based on Prolog predicates that define queries for patterns and antipatterns queries are able to include both structural and behavioural conditions

Example: Observer pattern definition in [Go4]

Example: Our Observer pattern detection observerPattern(Project, SubjectN, ObserverN, ConcrSubjsN, ConcrObserversN, UpdateMsN, AttDetMeths,NotifyMeth):- observer(Observer,ObserverN,Project), subject(Subject,SubjectN,Observer,AttDetMeths, NotifyMeth,UpdateMsN), findall(X,concreteSubject(_,X,Subject), ConcrSubjsN), findall(Y,concreteObserver(_,Y,Observer), ConcrObserversN). observer(Observer,ObserverN,Project):- myProject(Observer,Project,ObserverN), interfaceT(Observer), classDefT(Observer,_,_,UpdateMs), member(UpdateM,UpdateMs), methodDefT(UpdateM,_,_,_,_,_,_). subject(Subject,SubjectN,Observer, AttDetMeths,NotifyMeths,UpdateMeths):- classDefT(Subject,_,SubjectN,Fields), attachDetachMeths(Fields,Subject, Observer,AttDetMeths), findall(X,notifyMeth(_,X, Subject,Observer,_),NotifyMeths), NotifyMeths=[_|_], findall(Y,notifyMeth(_,_, Subject,Observer,Y),UpdateMeths), UpdateMeths=[_|_].

Example: Blob antipattern definition in [Brown] “The Blob is found in designs where one class monopolizes the processing, and other classes primarily encapsulate data. This AntiPattern is characterized by a class diagram composed of a single complex controller class surrounded by simple data classes”

Example: Our Blob antipattern detection godClass(Project,GO):- myProject(Cls,Project,GO), cycloClass(Cls,V), V>55, callToDataClass(Cls), classDefT(Cls,_,GO,Fields), length(Fields,Nr), Nr>=25. callToDataClass(GO):- methodDefT(Meth,GO,_,_,_,_,_), getFieldT(_,_,Meth,_,_,Field), not(fieldDefT(Field,GO,_,_,_)),!. callToDataClass(GO):- methodDefT(Meth,GO,_,_,_,_,_), callT(_,_,Meth,_,_,_,Field), setMethod(Field), not(fieldDefT(Field,GO,_,_,_)),!. callToDataClass(GO):- methodDefT(Meth,GO,_,_,_,_,_), callT(_,_,Meth,_,_,_,Field), getMethod(Field), not(fieldDefT(Field,GO,_,_,_)),!.

Detection results for patterns JHotDraw 6.0b.1 Java AWT 1.3 Java Swing 1.4 Java io Java net Apache Ant OPOPOPOPOPOP Observer Singleton Strategy Adapter Decorator

Detection results for antipatterns JHotDraw 6.0b.1 Java AWT 1.3 Java Swing 1.4 Java io Java net Apache Ant OD/iPO O O O O DataClass 10iP CallSuper Blob 13D/iP Refused Interface 25iP Yoyo Poltergeist

Conclusion In this article we propose detection methods for a set of patterns and antipatterns, using a logic-based approach. The main advantage of this approach is the simplicity of defining Prolog predicates able to describe both structural and behavioural aspects of patterns and antipatters. This advantage becomes more visible in the case of patterns and antipatterns that are characterised not only by structural aspects, but also by complex behavioural aspects that are difficult or not possible to describe by code metrics.