教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 教育文库 >

A critique of cohesion measures in the object-oriented parad(3)

来源:网络收集 时间:2026-05-21
导读: Cohesion refers to the relatedness of a module's components. In the object-oriented paradigm, cohesion refers to the relatedness among the methods of a class. Most of the current measures of cohesion

Cohesion refers to the "relatedness " of a module's components. In the object-oriented paradigm, cohesion refers to the "relatedness " among the methods of a class. Most of the current measures of cohesion in the object-oriented paradig

Buxton and Macro 10] extended the original seven levels of cohesion to include another type of cohesion which included modules that encapsulate abstract data types. They called this abstract cohesion or data cohesion. Fenton 18], describes such cohesion as a completely di erent type of cohesion and disagrees that it is an extension of the original seven levels of cohesion. This type of cohesion characterizes a data type as cohesive because the operations are performed on a single object. Thus a module in this case can perform a variety of functions, which are related by the abstract data type they characterize. Unlike the procedural programming paradigm where a module is de ned to be a procedure or a function, in the object-oriented paradigm we de ne a module to be a class. A class with a private representation of data elements and a public set of methods is referred to as an abstract data type. A class has several methods that perform certain functions on the class data type. Consider the list class described in Figure 2.1. Here we see that each method of the class uses the data elements head and tail to de ne various operations that can be performed on a LIST of objects, such as, append, remove, and is empty. All the methods are operating on a single LIST object. The list class encapsulating the abstract data type, LIST. Hence, the list class can be considered to be a cohesive class.

5

Cohesion refers to the "relatedness " of a module's components. In the object-oriented paradigm, cohesion refers to the "relatedness " among the methods of a class. Most of the current measures of cohesion in the object-oriented paradig

list::list(){ head= NULL; tail= NULL;} list::~list(){ remove();} void list::append(Type someitem){ item *pt; pt= new item(someitem); assert (pt != 0); if (is_empty()){ head= pt;} else{ tail->next= pt;} pt->next= NULL; tail= pt;} void list::remove(){ item *pt; item *temp; pt= head; while (pt){ temp= pt; pt= pt->next; delete(temp);} head= tail= NULL; cout<<"Removed all list elements"<<"\n";} boolean list::is_empty(){ if (head== NULL) return(true) else return(false);}

6

Figure 2.1: LIST class encapsulates abstract data type LIST and performs all operations on a LIST of objects as presented in a standard text 27].

Cohesion refers to the "relatedness " of a module's components. In the object-oriented paradigm, cohesion refers to the "relatedness " among the methods of a class. Most of the current measures of cohesion in the object-oriented paradig

Chapter 3

Existing Cohesion Measures in the Object-Oriented ParadigmHer

e we will be presenting some measures that have been proposed by researchers for measuring cohesion in the object-oriented paradigm. Some of the measures like LCOM, Connectivity metric, Chen and Lu's cohesion measure, and Bieman and Kang's cohesion measure are claimed to measure cohesion in the object-oriented paradigm. We, too, propose a cohesion measure in the object-oriented paradigm which is a modi cation of the slice-based functional cohesion measure in the procedural paradigm.

3.1 The Lack of Cohesion in Methods MetricChidamber and Kemerer 12] have proposed a cohesion measure called Lack of Cohesion in Methods, LCOM, based on the number of disjoint sets of instance variables that are used by the method. The cohesion of the class is inversely related to the number of disjoint sets, i.e., the smaller the number of disjoint sets the more cohesive the class is assumed to be. Li and Henry 19] attempted to rephrase the de nition of LCOM given by Chidamber and Kemerer in order to overcome the ambiguity in the original de nition. Chidamber and Kemerer 13] later revised their own de nition for LCOM and formally restated it as follows: Consider a class C1 with n methods M1, M2, . . ., Mn . Let Ij= set of instance variables used by the method Mj . There are n such sets I1,...,In. Let P= f (Ii,Ij ) j Ii\ Ij=;g and Q= f (Ii,Ij ) j Ii\ Ij 6=; g If all n sets I1,...,In are; then let P= 0.

LCOM=

(

jP j? jQj; if jP j> jQj0 otherwise 7

Cohesion refers to the "relatedness " of a module's components. In the object-oriented paradigm, cohesion refers to the "relatedness " among the methods of a class. Most of the current measures of cohesion in the object-oriented paradig

LCOM= 0 indicates a cohesive class since all the methods share instance variables. Hence the class need not be split. For LCOM> 0, the class needs to be or can be split into two or more classes since the instance variables belong in disjoint sets.

3.2 Connectivity MetricHitz and Montazeri 21], present a graph theoretic version of the cohesion metric proposed by Chidamber and Kemerer. They formulate a regression model for measuring the quality of software both at run-time and during the maintenance phase based on their metric. They de ne LCOM as follows: Consider a class X with a set of instance variables, IX, and a set of methods of the class, MX . Let GX (V,E) be a simple undirected graph representing the methods of the class, where V= MX and E= f(m; n) 2 V V j (9 i 2 IX: (m accesses i)^ (n accesses i)) _ (m calls n) _ (n calls m)g LCOM(X) is then de ned as the number of connected components of GX, where 1 LCOM (X ) jMX j where\m accesses i" means that m uses instance variable i.\m calls n" means that they share a common instance variable. For classes with more than two methods, they re ne the LCOM further to be able to measure the structural di erence between the methods of a set of classes with the same val …… 此处隐藏:6296字,全部文档内容请下载后查看。喜欢就下载吧 ……

A critique of cohesion measures in the object-oriented parad(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/108005.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)