77379433 object oriented metrics

Download 77379433 Object Oriented Metrics

If you can't read please download the document

Upload: ritesh-dhameja

Post on 27-Sep-2015

212 views

Category:

Documents


0 download

DESCRIPTION

metrics

TRANSCRIPT

Object Oriented Metrics(A Survey Approach) Seyyed Mohsen Jamali Department of Computer Engineering Sharif University of Technology January 2006 Tehran IranAbstract Given the central role that software development plays in the deliveryand application of information technology, managers are increasingly focusing onprocess improvement in the software development area. This demand has spurred the provision of a number of new and/or improved approaches to software development, with perhaps the most prominent being object-orientation (OO). In addition,the focus on process improvement has increased the demand for software measures,or metrics with which to manage the process. The need for such metrics is particularly acute when an organization is adopting a new technology for which established practices have yet to be developed. This research addresses these needs through the development and implementation of a suite of metrics for OO design. Index Terms Object Oriented, Design, Development, Metric, Measure, Coupling, Cohesion, Complexity, Size1. IntroductionObject-Oriented Analysis and Design of software provide many benefits such as reusability, decomposition of problem into easily understood object and the aidingof future modifications. But the OOAD software development life cycle is not easier than the typical procedural approach. Therefore, it is necessary to providedependable guidelines that one may follow to help ensure good OO programming practices and write reliable code. Object-Oriented programming metrics is an aspect to be considered. Metrics to be a set of standards against which one can measure the effectiveness of Object-Oriented Analysis techniques in the design of a system. Five characteristics of Object Oriented Metrics are as following: Localization operations used in many classes Encapsulation metrics for classes, not modules Information Hiding should be measured & improved Inheritance adds complexity, should be measured Object Abstraction metrics represent level of abstractionWe can signify nine classes of Object Oriented Metrics. In each of then an aspect of the software would be measured: Size Population (# of classes, operations)Volume (dynamic object count) Length (e.g., depth of inheritance) Functionality(# of user functions) Complexity How classes are interrelated Coupling # of collaborations between classes, number of method calls, etc. SufficiencyDoes a class reflect the necessary properties of the problem domain? Completeness Does a class reflect all the properties of the problem domain? (for reuse) Cohesion Do the attributes and operations in a class achieve a single, well-definedpurpose in the problem domain? Primitiveness (Simplicity) Degree to which classoperations cant be composed from other operations Similarity Comparison of structure, function, behavior of two or more classes Volatility The likelihood that achange will occur in the design or implementation of a classChidamber and Kemerer metrics suite for OO Design is the deepest research in OOmetrics investigation. s They have defined six metrics for the OO design. In this section well have a complete description of their metrics: Metric 1: WeightedMethods per Class (WMC) Definition: Consider a Class C1, with methods M1... Mn that are defined in the class. Let c1... cn be the complexity of the methods. Then:n2. Chidamber & Kemerer s Metrics SuiteWMC =i =1ciIf all method complexities are considered to be unity, then WMC = n, the numberof methods. Theoretical basis: WMC relates directly to Bunge 1 definition of complexity of a thing, since methods are s properties of object classes and complexity is determined by the cardinality of its set of properties. The number of methods is, therefore, a measure of class definition as well as being attributes ofa class, since attributes correspond to properties. Viewpoints The number of methods and the complexity of methods involved is a predictor of how much time andeffort is required to develop and maintain the class. The larger the number ofmethods in a class the greater the potential impact on children, since childrenwill inherit all the methods defined in the class. Classes with large numbers ofmethods are likely to be more application specific, limiting the possibility ofreuse. Metric 2: Depth of Inheritance Tree (DIT) Definition: Depth of inheritance of the class is the DIT metric for the class. In cases involving multiple inheritance, the DIT will be the maximum length from the node to the root of the tree. Theoretical basis: DIT relates to Bunge notion of the scope of properties.DIT is a measure of how many s ancestor classes can potentially affect this class. Viewpoints: The deeper a class is in the hierarchy, the greater the number ofmethods it is likely to inherit, making it more complex to predict its behavior. Deeper trees constitute greater design complexity, since more methods and classes are involved. The deeper a particular class is in the hierarchy, the greaterthe potential reuse of inherited methods.The ontological principles proposed by Bunge in his Treatise on Basic Philosophy form the basis of the concept of objects. While Bunge did not provide specific ontological definitions for object oriented concepts, several recent researchers have employed his generalized concepts to the object oriented domain.1Metric 3: Number of children (NOC) Definition: NOC = number of immediate sub-classes subordinated to a class in the class hierarchy. Theoretical basis: NOC relates to the notion of scope of properties. It is a measure of how many subclassesare going to inherit the methods of the parent class. Viewpoints: Greater the number of children, greater the reuse, since inheritance is a form of reuse. Greater the number of children, the greater the likelihood of improper abstraction of the parent class. If a class has a large number of children, it may be a caseof misuse of sub-classing. The number of children gives an idea of the potentialinfluence a class has on the design. If a class has a large number of children,it may require more testing of the methods in that class. Metric 4: Coupling between object classes (CBO) Definition: CBO for a class is a count of the numberof other classes to which it is coupled. Theoretical basis: CBO relates to the notion that an object is coupled to another object if one of them acts on the other, i.e., methods of one use methods or instance variables of another. As statedearlier, since objects of the same class have the same properties, two classesare coupled when methods declared in one class use methods or instance variablesdefined by the other class. Viewpoints: Excessive coupling between object classes is detrimental to modular design and prevents reuse. The more independent a class is, the easier it is to reuse it in another application. In order to improve modularity and promote encapsulation, inter-object class couples should be kept to a minimum. The larger the number of couples, the higher the sensitivity tochanges in other parts of the design, and therefore maintenance is more difficult. A measure of coupling is useful to determine how complex the testings of various parts of a design are likely to be. The higher the inter-object class coupling, the more rigorous the testing needs to be. Metric 5: Response for a Class (RFC) Definition: RFC = | RS | where RS is the response set for the class. Theoretical basis: The response set for the class can be expressed as: RS = { M } all i{ Ri } where { Ri } = set of methods called by method i and { M } = set of all methods in the class The response set of a class is a set of methods that can potentially be executed in response to a message received by an object of that class26. The cardinality of this set is a measure of the attributes of objects in the class. Since it specifically includes methods called from outside the class, it is also a measure of the potential communication between the class and other classes. Viewpoints: If a large number of methods can be invoked in response to amessage, the testing and debugging of the class becomes more complicated sinceit requires a greater level of understanding required on the part of the tester. The larger the number of methods that can be invoked from a class, the greaterthe complexity of the class. A worst case value for possible responses will assist in appropriate allocation of testing time. Metric 6: Lack of Cohesion in Methods (LCOM) Definition: Consider a Class C1 with n methods M1, M2..., Mn. Let {Ij} = set of instance variables used by method Mi. There are n such sets {I1},...{In}. Let P = { (Ii,Ij) | Ii Ij = } and Q = { (Ii,Ij) | Ii Ij _ }. If all n sets{I1},... {In} are then let P = . LCOM = |P| - |Q|, if |P| > |Q| = 0 otherwise28Example: Consider a class C with three methods M1, M2 and M3. Let {I1} = {a,b,c,d,e} and {I2} = {a,b,e} and {I3} = {x,y,z}. {I1} {I2} is non-empty, but {I1} {I3} and {I2} {I3} are null sets. LCOM is the (number of null-intersections - number of non-empty intersections), which in this case is 1. Theoretical basis: Thisuses the notion of degree of similarity of methods. The degree of similarity fortwo methods M1 and M2 in class C1 is given by: () = {I1} {I2} where {I1} and {I2} are the et of intance variable ued by M1 and M2The LCOM i a count of the number of method pair whoe imilarity i 0 (i.e. ()i a null et) minu the count of method pair whoe imilarity i not zero. Thelarger the number of imilar method, the more coheive the cla, which i conitent with traditional notion of coheion that meaure the interrelatedne between portion of a program. If none of the method of a cla diplay any intance behavior, i.e. do not ue any intance variable, they have no imilarity and the LCOM value for the cla will be zero. The LCOM value provide a meaureof the relative diparate nature of method in the cla. A maller number of dijoint pair (element of et P) implie greater imilarity of method. LCOM iintimately tied to the intance variable and method of a cla, and thereforei a meaure of the attribute of an object cla. Viewpoint: Coheivene of method within a cla i deirable, ince it promote encapulation. Lack of coheion implie clae hould probably be plit into two or more ub-clae. Anymeaure of diparatene of method help identify flaw in the deign of clae. Low coheion increae complexity, thereby increaing the likelihood of error during the development proce. The MOOD metric et refer to a baic tructural mechanim of the OO paradigm a encapulation ( MHF and AHF ), inheritance( MIF and AIF ), polymorphim ( PF ) , meage-paing ( CF ) and are expreeda quotient. The et include the following metric: Method Hiding Factor ( MHF ) MHF i defined a the ratio of the um of the inviibilitie of all methoddefined in all clae to the total number of method defined in the ytem under conideration. The inviibility of a method i the percentage of the total clae from which thi method i not viible. note : inherited method not conidered. Attribute Hiding Factor ( AHF ) AHF i defined a the ratio of the um of the inviibilitie of all attribute defined in all clae to the total number of attribute defined in the ytem under conideration. Method Inheritance Factor ( MIF ) MIF i defined a the ratio of the um of the inherited method in allclae of the ytem under conideration to the total number of available method ( locally defined plu inherited) for all clae. Attribute Inheritance Factor ( AIF ) AIF i defined a the ratio of the um of inherited attribute in all clae of the ytem under conideration to the total number of available attribute ( locally defined plu inherited ) for all clae. Polymorphim Factor( PF ) PF i defined a the ratio of the actual number of poible different polymorphic ituation for cla Ci to the maximum number of poible ditinct polymorphic ituation for cla Ci. Coupling Factor ( CF ) CF i defined a the ratio of the maximum poible number of coupling in the ytem to the actual numberof coupling not imputable to inheritance.3. MOOD (Metric for Object Oriented Deign)4. Some Traditional MetricThere are many metric that are applied to traditional functional development. The SATC2, from experience, ha identified three of thee metric that are applicable to object oriented development: Complexity, Size, and Readability. To meaure the complexity, the cyclomatic complexity i ued.Software Aurance Technology Center (SATC) at NASA Goddard Space Flight Center2Metric 1: Cyclomatic Complexity (CC) Cyclomatic complexity (McCabe) i ued to evaluate the complexity of an algorithm in a method. It i a count of the numberof tet cae that are needed to tet the method comprehenively. The formula for calculating the cyclomatic complexity i the number of edge minu the numberof node plu 2. For a equence where there i only one path, no choice or option, only one tet cae i needed. An IF loop however, ha two choice, if the condition i true, one path i teted; if the condition i fale, an alternative path i teted. Figure 1 how a method with a low cyclomatic complexity i generally better. Thi may imply decreaed teting and increaed undertandability orthat deciion are deferred through meage paing, not that the method i notcomplex. Cyclomatic complexity cannot be ued to meaure the complexity of a cla becaue of inheritance, but the cyclomatic complexity of individual methodcan be combined with other meaure to evaluate the complexity of the cla. Although thi metric i pecifically applicable to the evaluation of Complexity, italo i related to all of the other attributeFigure 1 Metric 2: Size Size of a cla i ued to evaluate the eae of undertanding of code by developer and maintainer. Size can be meaured in a variety of way. Thee include counting all phyical line of code, the number of tatement, the number of blank line, and the number of comment line. Line of Code(LOC) count all line. Non-comment Non-blank (NCNB) i ometime referred to a Source Line of Code and count all line that are not comment and not blank. Executable Statement (EXEC) i a count of executable tatement regardle of number of phyical line of code. For example, in FORTRAN and IF tatement may bewritten: IF X=3 THEN Y=0 Thi example would be 3 LOC, 3 NCNB, and 1 EXEC. Executable tatement i the meaure leat influenced by programmer or language tyle.Therefore, ince NASA program are frequently written uing multiple language,the SATC ue executable tatement to evaluate project ize. Threhold for evaluating the meaning of ize meaure vary depending on the coding language uedand the complexity of the method. However, ince ize affect eae of undertanding by the developer and maintainer, clae and method of large ize will alway poe a higher rik. Metric 3: Comment Percentage The line count done to compute the Size metric can be expanded to include a count of the number of comment, both on-line (with code) and tand-alone. The comment percentage i calculated by the total number of comment divided by the total line of code le thenumber of blank line. Since comment ait developer and maintainer, highercomment percentage increae undertandability and maintainability.5. Complexity Metric and Model5.1 Haltead' Software Science The Software Science developed by M.H.Haltead principally attempt to etimate the programming effort. The meaurable and countable propertie are: n1 = number of unique or ditinct operator appearing in that implementation n2 = number of unique or ditinct operand appearing in that implementation N1 = total uage of all of the operator appearing in that implementation N2 = total uage of all of the operand appearing in that implementationFrom thee metric Haltead define: I. the vocabulary n a n = n1 + n2 II. theimplementation length N a N = N1 + N2 Operator can be "+" and "*" but alo anindex "[...]" or a tatement eparation "..;..". The number of operand conitof the number of literal expreion, contant and variable. 5.2 Length Equation It may be neceary to know about the relationhip between length N and vocabulary n. Length Equation i a follow. " ' on N mean it i calculated ratherthan counted : " N ' n1log2n1 + n2log2n2 = It i experimentally oberved that N' give a rather cloe agreement to program length. 5.3 Quantification of Intelligence Content The ame algorithm need more conideration in a low level programming language. It i eaier to program in Pacal rather than in aembly. Theintelligence Content determine how much i aid in a program. In order to findQuantification of Intelligence Content we need ome other metric and formula:Program Volume: Thi metric i for the ize of any implementation of any algorithm. V = Nlog2n Program Level: It i the relationhip between Program Volume andPotential Volume. Only the mot clear algorithm can have a level of unity. L = V* / V Program Level Equation: i an approximation of the equation of the ProgramLevel. It i ued when the value of Potential Volume i not known becaue it ipoible to meaure it from an implementation directly. L ' n*1n2 / n1N2 = Intelligence Content I = L ' V = (2n2 / n1N2 ) x (N1 + N2)log2(n1 + n2) x In thi equation all term on the right-hand ide are directly meaurable from any expreion of an algorithm. The intelligence content i correlated highly with the potential volume. Conequently, becaue potential volume i independent of the language, the intelligence content hould alo be independent. 5.4 Programming EffortThe programming effort i retricted to the mental activity required to convertan exiting algorithm to an actual implementation in a programming language. Inorder to find Programming effort we need ome metric and formula:Potential Volume: i a metric for denoting the correponding parameter in an algorithm' hortet poible form. Neither operator nor operand can require repetition. V ' (n*1 + n*2 ) log2 ( n*1 + n*2 ) = Effort Equation The total numberof elementary mental dicrimination i: E = V / L = V2 / V If we express it: The implementation of any algorithm consists of N selections (nonrandom > of a vocabulary n. a program is generated by making as many mental comparisons as the program volume equation determines, because the program volume V is a measure of it. Another aspect that influences the effort equation is the program difficulty.Each mental comparison consists of a number of elementary mental discriminations. This number is a measure for the program difficulty. Time Equation A conceptconcerning the processing rate of the human brain, developed by the psychologistJohn Stroud, can be used. Stroud defined a moment as the time required by the human brain to perform the most elementary discrimination. The Stroud number S isthen Stroud moments per second with 5