130 likes | 343 Vues
Stereotype Identification. November 27 th , 2012 Erik Fredericks. Stereotypes. Abstraction of class’ role/responsibility in a system Useful in maintenance and software evolution Can show collaboration between classes in design patterns May be used to identify both methods and classes
E N D
Stereotype Identification November 27th, 2012 Erik Fredericks
Stereotypes • Abstraction of class’ role/responsibility in a system • Useful in maintenance and software evolution • Can show collaboration between classes in design patterns • May be used to identify both methods and classes • Note: authors’ work only covered C++ classes/methods
General Method Stereotypes [1] • Structural • Provide or support structure of classes • Creational • Create or destroy objects • Collaborational • Characterize communication between objects • How they’re controlled within system • Degenerate • Limited structural or collaborational types
Sample Metric • To identify the stereotype Accessor::Get the following conditions need to be satisfied: • method is const • returns a data member • return type is primitive or container of primitives
Method • Convert source code to XML (srcML) • Convert metrics to XPath queries • Stereotype predicate • /** @stereotype predicate [searching for --^] */ • boolisValidLabel(const string& label) const; • Annotate source code with results • function[specifier='const’] • [type/name='bool'] • [descendant::return/expr/name= • descendant::decl/name • or descendant::return/expr='false' • or descendant::return/expr='true'] [not(contains(descendant::type,'*'))]
Class Stereotypes [2] • Entity • Encapsulates data and behavior • Contains accessors/mutators • Minimal Entity • Only get/set methods • Trivial entities (Point) • Data Provider • Encapsulates data • Provides accessors
Class Stereotypes • Commander • Encapsulates data • Consists of mutators • Typically complex object states changes • Boundary • Communication methods • Large percentage collaborational methods • Low percentage of controller and factory methods • Factory • Object creator • Mostly factory methods
Class Stereotypes • Controller • Functionality or processing of external object data • Pure Controller • 100% factory or controller methods • Only works on data outside of itselfLarge Class • Contains too many responsibilities • Typically measured by LOC, number of attributes/methods • Multiple roles, highly collaborative • Lazy Class • Does too little • Contains significant number of degenerates
Class Stereotypes • Degenerate • Methods don’t read/write to object state • Half or more are incidental or empty classes • Data Class • Only provides get/set methods • Passively stores data • Small Class • Only incorporates one to two methods
Sample Metrics • Factory: • |factory| > (2/3) ∗ |methods| • Class is identified as a factory class if: • Amount of factory methods is larger than 2/3 * the total amount of methods • Data Provider: • Consists mostly of accessors: • |accessors| > 2 * |mutators| • and low control of other classes • |accessors| > 2 * (|controller| + |factory|)
Toolsets • Conversion to XML • srcML (http://www.sdml.info/projects/srcml/) • The following do not have open-source releases, and would need to be requested should this be considered useful • Classifying method stereotypes • StereoCode • Classifying class stereotypes • StereoClass
Current Plan • Transform Sumit’s annotated code into an ontology • Work from the ground up • Make use of keywords from Cybox specification • Ensure that BAE has access to necessary folders on MSU server
References • [1] N. Dragan, M. L. Collard, and J. I. Maletic, "Reverse Engineering Method Stereotypes," in 22nd IEEE International Conference on Software Maintenance (ICSM'06), Philadelphia, Pennsylvania USA, 2006, pp. 24-34. • [2] Natalia Dragan, Michael L. Collard, and Jonathan I. Maletic. Automatic identification of class stereotypes. In Proceedings of the 2010 IEEE International Conference on Software Maintenance, ICSM ’10, pages 1–10, Washington, DC, USA, 2010. IEEE Computer Society.