Granularity can be understood as the level of division into which objects are built. To address in terms of high and low classification:
Lowgranularityisthedivisionintomanydetailsofobjects,commonlywithmanycompositionsandfewattributesperobject;highgranularityisthecoarserlevel,objectsgetmanyattributesandfewrelationships.
Imakeaparallelwiththerepresentationofinvoicesinsomecorporatesystems,maintainedwithtwoobjects:NotaFiscalNaoEmitida
andNotaFiscalEmitida
.Itseemstomeagoodexamplebecauseitdealswithtwoextremesofthesamedataandisconsistentwith this brief reference :
Building objects at the lowest level of granularity provides optimal flexibility, but may be unacceptable in terms of performance and memory usage. (free translation)
The first has only a few fields of the invoice and refers to dozens of other entities such as Cliente
, Produto
, Empresa
, Endereco
, Imposto
. It has low granularity .
Once issued and no longer modified, and for performance purposes, historical consistency, and storage simplicity, NotaFiscalEmitida
has a copy of all relationship information stored in a single row in the database. The object has an absurd configuration with more than a hundred fields and no relation, but it is totally independent of any other entity and self-contained in its data. It has high granularity .