The mantra "Keep high cohesion and low coupling" (or some variant) is frequently tossed around. However, I find that it frequently conflicts with "Don't repeat yourself."
For example, I think we can all agree that it's a bad thing to re-implement std::string
or use C-strings, but doesn't including std::string
create another dependency and therefore increase coupling?
For another example, take std::stringstream
. It inherits from iostream
, which inherits from istream
and ostream
, which inherit from ios
, which inherits from ios_base
. Over all these derivations, it inherits a lot of functionality - enough to make re-implementing by hand a very bad idea. It also pulls the <ios>
and <istream>
headers even though only <sstream>
was included, thereby increasing coupling.
How can one keep coupling low without reinventing the wheel for each module?
EDIT: If the two concepts cannot coexist, which one should be favored?