Ho una domanda basata sui seguenti frammenti di "Codice pulito". Quelli sono stati citati prima, ma volevo fare una domanda di base.
1.
Data/Object Anti-Symmetry
(...) the difference between objects and data structures. Objects hide their data behind abstractions and expose functions that operate on that data. Data structure expose their data and have no meaningful functions. Go back and read that again. Notice the complimentary nature of the two definitions. They are virtual opposites. This difference may seem trivial, but it has far-reaching implications.
2.
Procedural code (code using data structures) makes it easy to add new functions without changing the existing data structures. OO code, on the other hand, makes it easy to add new classes without changing existing functions.
The complement is also true:
Procedural code makes it hard to add new data structures because all the functions must change. OO code makes it hard to add new functions because all the classes must change.
3.
(...) would be a lot less confusing if data structures simply had public variables and no functions, whereas objects had private variables and public functions. (...)
4.
Hybrids
This confusion sometimes leads to unfortunate hybrid structures that are half object and half data structure. They have functions that do significant things, and they also have either public variables or public accessors and mutators that, for all intents and purposes, make the private variables public, tempting other external functions to use those variables the way a procedural program would use a data structure. Such hybrids make it hard to add new functions but also make it hard to add new data structures. They are the worst of both worlds. Avoid creating them. They are indicative of a muddled design whose authors are unsure of—or worse, ignorant of—whether they need protection from functions or types.
E la domanda è: secondo Clean Code, va bene aggiungere un singolo costruttore a una struttura dati semplice?
Voglio seguire i consigli in modo molto preciso, ma trovo piuttosto noioso inizializzare ogni campo in una nuova riga. D'altra parte, l'aggiunta di un costruttore sta aggiungendo un metodo, che non è naturale per le strutture di dati. Forse essere costretti a nominare esplicitamente ciascuno dei campi inizializzati porta anche un certo valore.