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?

Сервис поддержки клиентов работает на платформе UserEcho