0
Отвечено

Primitive obsesion VS Data class

Nastasia Saby il y a 7 ans mis à jour par anonymous il y a 7 ans 1

I have the impression that finally in some way, fighting primitive obsession (for instance transforming an array in a small object) drives to create data classes.

I guess it is a bit subbtle, but I don't get it and to say the truth I prefer creating data classes than having a huge of arrays that make sens together and represent more concepts than arrays.


I really would like to discuss it with you. I would be really pleased to have some other points of view. I'm trying to improve my skills.

Solution

Solution
Отвечено

Hey Nastasia,


Great question! I think they both could act as an intermediate step to a cleaner code. Here's example:


1. You have a Primitive obsession situation(say, lots of arrays). It smells bad.

2. You turn arrays into classes.

3. Now you have a lot of Data classes. Smells better, but not that good yet.

4. You add some behaviors to data classes, and merge them together if both have similar purpose.

5. Bam! Now, you've got clean code and nice classes.


Does this make sense?

JE SUIS SATISFAIT

Thanks for you answer

Note de satisfaction par Nastasia Saby il y a 7 ans
Solution
Отвечено

Hey Nastasia,


Great question! I think they both could act as an intermediate step to a cleaner code. Here's example:


1. You have a Primitive obsession situation(say, lots of arrays). It smells bad.

2. You turn arrays into classes.

3. Now you have a lot of Data classes. Smells better, but not that good yet.

4. You add some behaviors to data classes, and merge them together if both have similar purpose.

5. Bam! Now, you've got clean code and nice classes.


Does this make sense?