Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Cohesion is usually measured using one of the LCOM (Lack of cohesion) metrics, the original LCOM metric came from Chidamber and Kemerer. See for example: <a href="http://www.computing.dcu.ie/~renaat/ca421/LCOM.html" rel="noreferrer">http://www.computing.dcu.ie/~renaat/ca421/LCOM.html</a></p> <p>A more concrete example: If a class has for example one private field and three methods; when all three methods use this field to perform an operation then the class is very cohesive.</p> <p>Pseudo code of a cohesive class:</p> <pre><code>class FooBar { private SomeObject _bla = new SomeObject(); public void FirstMethod() { _bla.FirstCall(); } public void SecondMethod() { _bla.SecondCall(); } public void ThirdMethod() { _bla.ThirdCall(); } } </code></pre> <p>If a class has for example three private fields and three methods; when all three methods use just one of the three fields then the class is poorly cohesive.</p> <p>Pseudo code of a poorly cohesive class:</p> <pre><code>class FooBar { private SomeObject _bla = new SomeObject(); private SomeObject _foo = new SomeObject(); private SomeObject _bar = new SomeObject(); public void FirstMethod() { _bla.Call(); } public void SecondMethod() { _foo.Call(); } public void ThirdMethod() { _bar.Call(); } } </code></pre> <p>The class doing one thing principle is the <a href="http://www.objectmentor.com/resources/articles/srp.pdf" rel="noreferrer">Single Responsibility Principle</a> which comes from Robert C. Martin and is one of the <a href="http://en.wikipedia.org/wiki/Solid_%28object-oriented_design%29" rel="noreferrer">SOLID</a> principles. The principle prescribes that a class should have only one reason to change.</p> <p>Staying close to the Single Responsibility Principle could possibly result in more cohesive code, but in my opinion these are two different things.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload