480 likes | 673 Views
Measuring Class Coupling and Cohesion: A Formal Metamodel Approach. by Simon Moser and Vojislav B. Misic (1997) Synopsis by Rand Williams. Abstract. This presents software quality metrics : Coupling Cohesion Defined in the terms of
E N D
Measuring Class Coupling and Cohesion: A Formal Metamodel Approach by Simon Moser and Vojislav B. Misic (1997) Synopsis by Rand Williams
Abstract • This presents software quality metrics: • Coupling • Cohesion • Defined in the terms of • Functional Dependencies in a Formal Metamodel of Object-Oriented Systems
Contents • Introduction • Model Definition Part I • Model Definition Part II • Measuring Design Quality • Component Sizes • Coupling • Cohesion • Experiment and Explanation • Conclusion
1. Introduction What are Software Quality Metrics • Software Quality Metrics are used • To measure design quality • To estimate, monitor, and control quality
1. Introduction What are Formal methods • Formal methods • Mathematical language • Express system structure and behavior • The authors of this paper use Z
1. Introduction What is Meta-Modeling • Meta-Modeling is an iterative method of • Model Definition • Model Refinement • Definitions are layered, i.e. compositional • Abstract refined to specific
2. Model Definition Part I • Abstract Formal-Metamodel • Structure of interrelated objects • Object is defined by • Interfaces (structure) • Implementations (behavior)
2. Model Definition Part I • The External Part (ExtPart) of an object • Interface used for • communication with other objects • represents the object • The Internal part (IntPart) of an object • Implementation
2. Model Definition Part I • Object must have one or both: • Interface • Implementation
2. Model Definition Part I • Objects define other objects • Relations: defines, use and usedBy
2. Model Definition Part I • Object encapsulation: contained objects retain their identity and are not a part of the container; for instance, a member variable.
2. Model Definition Part I • Uniqueness • Contained objects areunique within their container
3. Model Definition Part II • General Formal-Metamodel • For object-oriented systems • Abstract model is refined • Add concepts of object-oriented systems • Classes • Features • Inheritance
3. Model Definition Part II • Classes and Features • Types of the objects • Feature is a Variable or Method
3. Model Definition Part II • Inheritance subset of defines relation • Relations: • parentOf (many to one) • Children (one to one (set))
3. Model Definition Part II • Inheritance of Features • Transitive closure inheritedTo • Over the parentOf and classOf • Tells which features are defined for any particular child class
4. Measuring Design Quality • Coupling and Cohesion • Used for assessing system design quality for more than two decades • Industry Wisdom: “the [system] with the lower coupling and higher cohesion is of better quality.”
4. Measuring Design Quality • General definition of Coupling • Coupling = the (relative) degree of dependence of one object on another • Example: The (relative) amount that PlanetaryScale class depends on the Astronaut class
4. Measuring Design Quality • General definition of Cohesion • Cohesion = the (relative) degree to which ‘all elements of an object contribute to performing a single well defined function’ • Example: The (relative) amount that Astronaut class is defined within itself.
4. Measuring Design Quality • 4.1. Calculating component sizes • External size • Internal size • Total size • The total size of any object • Sum of Internal and External
4. Measuring Design Quality • The external size • Effort required to use object • Correlates to size of interface • For a library or project objectIf has interface, size is sum
4. Measuring Design Quality • For a library or project objectIf no interface, size is 1
4. Measuring Design Quality • The internal size • Effort to implement object • For a project object • Sum of external sizes of defining objects
4. Measuring Design Quality • For a language or library object • Internal size is 0 • For a language object • External size is 1
4. Measuring Design Quality • 4.2. Class coupling • Active Coupling • Passive Coupling • Coupling measures the degree of dependence of a given object on other objects
4. Measuring Design Quality • Active Coupling • External size of C2 relative to Internal size of C1
4. Measuring Design Quality • Passive Coupling • Amount of External size of C1 relative to total External size of C1, used in C2
4. Measuring Design Quality • 4.3. Class Cohesion • Internal Cohesion • External Cohesion • Cohesion denotes the degree to which ‘all elements of an object contribute to performing a single well defined function’
4. Measuring Design Quality • Internal Cohesion • Amount of Coupling of object to itself
4. Measuring Design Quality • The Siblings of a feature • The set of other features contained in the same class
4. Measuring Design Quality • Measurement Sigma is similarity of usage of a feature relative to that of its siblings
4. Measuring Design Quality • The External Cohesion • The average similarity of the usage of the class’s features
5. Experiment and Explanation • The authors perform a simple empirical experiment on a set of Java classes • A utility class Astronaut • A main class PlaneteryScale
5. Experiment and Explanation • The authors perform a simple empirical experiment on a set of Java classes • A utility class Astronaut • A main class PlaneteryScale
5. Experiment and Explanation • The PlanetaryScale class • contains an instance of the Astronaut class (as a variable = a Feature) class PlaneteryScale { private Astronaut armstrong; … }
5. Experiment and Explanation • The PlanetaryScale class • Uses Features (methods) of Astronaut in several of its own features class PlaneteryScale { void calculateWeight() { armstrong = new Astronaut (getEarthWeight()); } … }
5. Experiment and Explanation • The Astronaut class • Does not contain PlanetaryScale class • Does not use PlanetaryScale class
5. Experiment and Explanation • Coupling and Cohesion measuresAstronaut and PlanetaryScale classes
5. Experiment and Explanation • Active Coupling – inter-dependency 20% of PlanetaryScale is Astronaut0% of Astronaut is PlanetaryScale
5. Experiment and Explanation • Passive Coupling – efficiency of use71% Astronaut used in PlanetaryScale0% PlanetaryScale used in Astronaut
5. Experiment and Explanation • Internal Cohesion – self definition50% of Astronaut defined in itself33% of PlanetaryScale defined in itself
5. Experiment and Explanation • External Cohesion – feature average67% Astronaut 97% PlanetaryScale • The average similarity of the usage of the class’s features
6. Conclusion • Measuring Class Coupling and Cohesion: A Formal Metamodel Approach by Simon Moser and Vojislav B. Misic presents • General Formal Metamodel of OO systems • Definition of software quality metrics, Coupling and Cohesion • For use in measuring design quality
6. Conclusion • Readers opinion: • “Although the metrics and definitions appear thorough, the paper is very light in empirical research, results, and explanations. Further analysis of the definitions and implications would be required, in this readers opinion, to validate and verify both the accuracy and utility of the defined model and metrics.”
References • Moser, S.; Misic, V.B.; , "Measuring class coupling and cohesion: a formal metamodel approach ," Software Engineering Conference, 1997. Asia Pacific ... and International Computer Science Conference 1997. APSEC '97 and ICSC '97. Proceedings , vol., no., pp.31-40, 2-5 Dec 1997doi: 10.1109/APSEC.1997.640159 URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=640159&isnumber=13814