which metric(s) show the difference between object-oriented and procedural code
Asked Answered
T

2

6

Which metric(s) could help to indicate that i have procedural code instead of object-oriented code? I would like to have a set of simple metrics, which indicate with a high probability, that the analyzed code contains procedural transaction scripts and an anemic domain model instead of following sound object-oriented design principles.

Would be happy about any set of useful metrics and tools for measuring.

Thanks, Thomas!

Tillandsia answered 19/3, 2010 at 22:24 Comment(1)
How about the count of "class" tokens in the source code?Lickspittle
B
1

Some just out of my mind

  • relative number of interfaces, abstract classes, etc. (more OO)
  • member variable usage per method (more OO)
  • number of methods in which the same member variable is used (more OO)
  • quantity of static variables and methods (more procedural, specially static methods (some exceptions apply, like factories))
  • lines of code per class (more procedural)

These don't ensure your code is more OO or more procedural, but might find helping those.

Benzoic answered 19/3, 2010 at 22:33 Comment(0)
A
1

Cohesion and Coupling


Metrics focused on cohesion and coupling should give a good indication that your classes are real as opposed to collections of functions. There's a very readable paper here which I quote below to indicate why I think cohesion is a good metric:

"Cohesion refers to the relatedness" of module components. A highly cohesive component is one with one basic function. It should be difficult to split a cohesive component. Cohesion can be classified using an ordinal scale that ranges from the least desirable category (coincidental cohesion) to the most desirable (functional cohesion)."

The classic measurement of cohesion is Chidamber and Kemerer's "Lack of Cohesion in Methods" (LCOM). You can also look at Response for a Class (RFC) which measures the linkage between methods in a class.

You could consider design metrics such as NOC and DIT but my own experience is that they are too crude and easily confused by classes within a third-party framework.

You haven't said which language you use but there are some tools built around Eclipse so a quick web search for Eclipse based object oriented metrics should yield something useful

Acridine answered 22/3, 2010 at 8:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.