0
Answered

Primitive obsesion VS Data class

Nastasia 12 months ago • updated by Alexander Shvets 4 months ago 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.

Answer

Answer
Answered

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?

GOOD, I'M SATISFIED

Thanks for you answer

Satisfaction mark by Nastasia 12 months ago
Answer
Answered

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?