> Q How to get High Cohesion and Low Coupling, while designing in C++ ?
use OO. Refactor mercilessly. Read Constantine and Yourdon.
Be intelligent.
Cheers & hth.,
- Alf
--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!
Hello,
I believe a complete reply to the above question would require a small
essay. I think therefore that it would be more appropriate for you to
go through some reference material, and then, if needed,ask specific
questions - such as: 'how to reduce local coupling - when one module
modifies or relies on the internal workings of another module'.
http://en.wikipedia.org/wiki/Coupling_(computer_science)
http://en.wikipedia.org/wiki/Cohesion_(computer_science)
http://www.aui.ma/personal/~H.Kabaili/Publications/csmr-2001.pdf
Regards.
A.S.
Note that "refactor" means to run all unit tests between each tiny change. Any
other definition for it is just "churn" or "rework".
Or just use Test Driven Development. Tests work better when their targets are
easy to set-up. They make decoupling more convenient.
> http://en.wikipedia.org/wiki/Coupling_(computer_science)
Does it say "coupling means to change A you must also change B"?
> http://en.wikipedia.org/wiki/Cohesion_(computer_science)
Does it say "A and B share legitimate reasons to change, together"?
Defining those words in terms of change makes their definitions simple and
obvious, but WikiPedia probably cites sources who just go the long route...
Yes, four lines below the main title.
> >http://en.wikipedia.org/wiki/Cohesion_(computer_science)
>
> Does it say "A and B share legitimate reasons to change, together"?
Actually no. It is more concerned with responsibilities of a single
module of code, I believe along the line that 'each module should do
one main thing and do it well'.
> Defining those words in terms of change makes their definitions simple and
> obvious, but WikiPedia probably cites sources who just go the long route...
Who knows? The OP could be a student studying the theory or a
practitioner looking for best practice, but you may be right.
Regards,
A.S.
>>> http://en.wikipedia.org/wiki/Coupling_(computer_science)
>> Does it say "coupling means to change A you must also change B"?
>
> Yes, four lines below the main title.
Confucius say, when you go to flame WikiPedia, first dig two graves. (-:
>>> http://en.wikipedia.org/wiki/Cohesion_(computer_science)
>> Does it say "A and B share legitimate reasons to change, together"?
>
> Actually no. It is more concerned with responsibilities of a single
> module of code, I believe along the line that 'each module should do
> one main thing and do it well'.
I didn't say A and B were different modules. Yet the Single Responsibility
Principle is indeed more specific than "cohere"...
When you have found out how, also consider if you *need* them in the
specific case. In my opinion, C++ programmers (at least in the past)
have spent too much effort in this area.
/Jorgen
--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se> R'lyeh wgah'nagl fhtagn!