0
Відповідь надано

Primitive obsesion VS Data class

Nastasia Saby 7 років тому оновлено anonymous 7 років тому 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.

Відповідь

Відповідь
Відповідь надано

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?

ДОБРЕ, Я ЗАДОВОЛЕНИЙ

Thanks for you answer

Позначка задоволеності від Nastasia Saby 7 років тому
Відповідь
Відповідь надано

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?