U
U
UnknownHuman2016-06-16 15:40:16
OOP
UnknownHuman, 2016-06-16 15:40:16

What is the best way to organize classes with a large number of fields?

The question is this. There are entities that can have about 50 properties (this number may change periodically during the life cycle of the software). I see two main options for organizing such classes:
1. In the forehead: a class in which there are a lot of fields.
2. Create your own simple universal structure for storing the "field name" - "value" link (with the necessary methods for writing and searching) and push everything into an array or list, where each element is an instance of such a structure.
You can make both options work, but which way is better? Or are both bad, but is there a pattern that makes sense?
By the way, if the option "on the forehead" is not used for a large number of properties, then where is the boundary usually drawn in practice, are these properties many or few?
I have almost no "combat" development experience, so I ask for advice from experienced comrades.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Night, 2016-06-16
@maxtm

If the properties are known in advance, then use "on the forehead".
If the properties can change (for example, based on a reference book from the database), then the second option.

V
Vitaly Vitrenko, 2016-06-16
@Vestail

Pattern builder (Joshua Bloch) is probably what you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question