Message-ID: <194796018.21275.1394187140115.JavaMail.email@example.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_21274_184643819.1394187140114" ------=_Part_21274_184643819.1394187140114 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Cohesion is the degree to which the methods of a single class are tied t= ogether. When two methods in a class do not use a common attribute or a com= mon method, it means that they share nothing and should probably not belong= to the same class to respect the Si= ngle Responsibility Principle. In other words you can split your class = into several new classes to gain modularity at class level.
The LCOM4 (Lack of Cohesion of Methods) computation is based on Hitz &am= p; Montazeri. Here is a good introduction: http://www.aivosto.com/project/help/pm-oo-cohesion.html#LCOM4= .
The best value for this metric is 1.
Add the LCOM4 widget on your dashboard:
Project with one single class: Client.
The project has an average LCOM4 value of 2:
The Client class has an LCOM4 value of 2:
It shows that there should be two different objects: Client and Address.
After creating a new Address class and creating an Address<= /em> object in Client:
The LCOM4 of the project is down to the best value:
Thanks to the fact that Client and Address have an LCO= M4 value of 1:
See the following blog post: Clean Up Design at Class Level with Sonar.