Objects by Design Forums Here you can view your subscribed threads, work with private messages and edit your profile and preferences Registration is free! Calendar Find other members Frequently Asked Questions Search Home  
Objects by Design Forums : Powered by vBulletin version 2.3.5 Objects by Design Forums > Main Forums > Object-Oriented Calculator > cohesion and coupling
  Last Thread   Next Thread
Author
Thread Post New Thread    Post A Reply
cvduk
Junior Member

Registered: May 2002
Location:
Posts: 1

cohesion and coupling

Need a little help. Have the question "How has OOD helped with coupling and cohesion?" Can find plenty of definitions but no real answers. Any help would be greatly appreciated.

Cheers

Report this post to a moderator | IP: Logged

Old Post 05-09-2002 03:08 PM
cvduk is offline Click Here to See the Profile for cvduk Click here to Send cvduk a Private Message Find more posts by cvduk Add cvduk to your buddy list Edit/Delete Message Reply w/Quote
wellington
Member

Registered: Jun 2001
Location:
Posts: 37

This is a good question but hard to answer.

Generally speaking you want low-coupling and high-cohesion, as explained very nicely in Craig Larman's book, Applying UML and Patterns.

Using the calculator example from this forum, I will try to provide an example of low-coupling. Low-coupling means simply that only a few key classes know about eachother. In other words, classes only know what they have to know. The benefit of low-coupling is ease of maintenance. If there are changes to the interface for a class, relatively little impact is made on surrounding classes.

In the Object-Oriented Calculator, the model and view classes are separated into different packages by the same names. You can see the separation in the Calculator class diagram where the top half shows classes in the view and the bottom half shows classes in the model.

The only real coupling here is between the Calculator and the Cpu classes. Two methods on Cpu provide the main interface, enterOperation() and enterDigit(). This low coupling makes it very easy to provide different views and also to provide a testing framework. Everything from Cpu and below is a black-box; the view doesn't need to know anything about other classes in the model.

To see this low-coupling in the code, click on the Calculator class on the diagram and the source code will display in another window. You will see that only one class is imported from the model and that is Cpu. Calculator doesn't know about any other classes in the model.

Hope this helps for low-coupling. I will think of a good example for high-cohesion.

Report this post to a moderator | IP: Logged

Old Post 05-10-2002 10:05 AM
wellington is offline Click Here to See the Profile for wellington Click here to Send wellington a Private Message Visit wellington's homepage! Find more posts by wellington Add wellington to your buddy list Edit/Delete Message Reply w/Quote
pdstatha
Junior Member

Registered: Mar 2002
Location:
Posts: 2

So in other words, Low Coupling = Encapsulation ?????????

Report this post to a moderator | IP: Logged

Old Post 05-10-2002 01:59 PM
pdstatha is offline Click Here to See the Profile for pdstatha Click here to Send pdstatha a Private Message Visit pdstatha's homepage! Find more posts by pdstatha Add pdstatha to your buddy list Edit/Delete Message Reply w/Quote
SZ
Administrator

Registered: Apr 2001
Location: New York
Posts: 492

No, this is not necessarily true.

For instance, although the Cpu class may provide good encapsulation, there could be many classes in the view package which called the enterOperation() or enterDigit() methods, yielding high coupling between the view and the model. Instead, only the Calculator class is coupled with the Cpu class.

Although many concepts in OO are related, they are not necessarily equivalent. When I teach beginning students OO they invariably get confused by all the new terminology and try to equate terms. Once you get it though, it becomes very clear.

Report this post to a moderator | IP: Logged

Old Post 05-10-2002 06:34 PM
SZ is offline Click Here to See the Profile for SZ Click here to Send SZ a Private Message Visit SZ's homepage! Find more posts by SZ Add SZ to your buddy list Edit/Delete Message Reply w/Quote
All times are GMT. The time now is 10:29 AM. Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 

< Contact Us - Objects by Design >

Powered by: vBulletin Version 2.3.5
Copyright ©2000 - 2017, Jelsoft Enterprises Limited.
Copyright 1999-2005, Objects by Design, Inc.