Suppose I have a member function void A::foo(B const &b) where a class B instance is just a bunch of data. Would it not be better to remove the dependency between class A and class B by rewriting the member function like void A::foo(int var1, double var2, double var3)? Or could this modification be classified as a Primitive Obsession?
Asked
Active
Viewed 208 times
2
Martin Maat
- 18,652
2 Answers
3
It depends on which way the dependency goes. You do not want some library to depend on types in your application, this would defeat the purpose of having a library. But as long as the richer type's definition is in the library itself, this would just be regarded as strong typing, which is a good thing.
Martin Maat
- 18,652
1
Use a type like a struct if it is already available, and it matches the logic of the parameters. You wouldn’t use a random unrelated struct containing an Int and a double to replace two parameters.
gnasher729
- 49,096