Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 1 KB

lcom4.md

File metadata and controls

43 lines (32 loc) · 1 KB

lcom/lcom4

Ensures a value of so called LCOM4 to be less than 2 in a class.

Rule Details

This rule aims to keep methods in a class high cohesive by using LCOM4 metric. It suggests that the class needs to be split into two or more classes if LCOM4 > 1.

Examples of incorrect code for this rule:

// LCOM4 = 1
class A {
  foo() {
    return this.var1
  }

  bar() {
    return this.var1
  }
}

Examples of correct code for this rule:

// LCOM4 = 2
class A {
  foo() {
    return this.var1
  }

  bar() {
    return this.var2
  }
}

Further Reading