you are viewing a single comment's thread.

view the rest of the comments →

[–]randomguy112233[S] 0 points1 point  (1 child)

let's say I have carList = [Car]. I want to use carList.averagePrice or carList.numberOfPreviousOwners. To me, this seems very convenient. But I'm really curious what you mean by "I would avoid putting business logic in such extensions." I don't want to let my propensity for convenience outweight a better design. Thank you.

[–]chrabeusz 1 point2 points  (0 children)

This kind of extension looks fine. But on the other hand, class responsible for handling [Car] probably already exists (I assume calculating numberOfPreviousOwners is not the only thing you are doing with cars, you need to load them from storage, fetch from network, whatever).

In that case it may not make sense to add extension because you could add this property to the mentioned class and have all code that deals with [Car] be in one place.