3

According to The Pragmatic Programmer book "Orthogonality is closely related to the DRY principle". I'm not sure if I understand it the way the author wants the reader to. So I ask the question above.

For example, you have class A and class B. Both classes have similar methods. Using DRY principle, I made a class C, then moved the similar methods from class A and class B to class C, and assign class C as the parent class of A and B. Does it became not orthogonal?

1
  • Question is conceptual. programmers.SE is a better fit.
    – outis
    Mar 2, 2014 at 5:47

1 Answer 1

0

Firstly, subtyping is not primarily about code reuse (though that is a side-benefit). You don't have two classes descend from a third simply because they have some code in common; you do it when instances of the child classes should be able to be taken for instances of the parent class in all contexts (the subtype instances can be substituted for a supertype).

Secondly, Hunt & Thomas's use of the term "orthogonality" focuses on different modules, not design or implementation considerations within a module. More specifically, it has to do with the lack of interdependence between modules. Two modules are orthogonal if changes to one do not affect the other. More typically, "orthogonality" has a different meaning (language features can be combined arbitrarily, rather than disallowing certain features in certain contexts, or having different versions of the same operation for different types), and you'd speak of "coupling" (interdependence between modules, the inverse of H & T's "orthogonality") and "cohesion".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.