Lack of cohesion of methods
Cohesion metrics measure how well methods of a class are related to each other. A cohesive class has one responsibility. A non-cohesive class has more unrelated functions, thus more than one responsibility.
LCOM4 considers method as related with other method, when both of them use common attribute or method call. Methods are not compared with constructors / initializers eg. __init__, since they often involve all attributes. Also all inherited methods are ignored - as they come from different class.
Score:
==1 - indicates a cohesive class, which is the “good” class;
>=2 - indicates a problem. The class should be split into so many smaller classes;
==0 - happens when there are no methods in a class. This is also a “bad” class.
Usage
Just point it to a module or a package that needs to be measured:
bin/lcom src
This will result in such output:
Calculating LCOM using LCOM4
+---------------------------------+------+
| Method | LCOM |
+---------------------------------+------+
| src.command.FileSystem | 1 |
| src.command.LCOMFactory | 0 |
| src.command.Printer | 0 |
| src.command.PrinterFactory | 0 |
| src.command.Runner | 1 |
| src.command.STDOut | 0 |
| src.lcom.LCOM4 | 1 |
| src.lcom.LCOMAlgorithm | 0 |
| src.reflection.ClassReflection | 1 |
| src.reflection.MethodReflection | 1 |
| src.reflection.ModuleReflection | 1 |
| src.reflection.Reflection | 0 |
| src.reflection.ReflectionError | 0 |
+---------------------------------+------+
| Average | 0.46 |
+---------------------------------+------+
It is also possible to measure single module:
bin/lcom src/command.py
Or mix them:
bin/lcom src/command.py tests
Metadata
Release files for lcom 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lcom-0.1.0.tar.gz | 4.9 kB | Without provenance | Details for lcom-0.1.0.tar.gz |
Release files / lcom-0.1.0.tar.gz
| Download URL | lcom-0.1.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85f7e893b100f1d8e9f8cd6c5689c46d4cac49452551b3475e68a8f1ae22321d
|
|
BLAKE2b-256 checksum How to use checksums |
ea9df7516ee8e86921c2c0276d4c1ddce425234258ab91628c7cf38ce5c43e8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for lcom 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.