File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Low Cohesion or Tight Coupling? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Low Cohesion or Tight Coupling?" Watch "Low Cohesion or Tight Coupling?" New topic
Author

Low Cohesion or Tight Coupling?

Seema Gaurav
Ranch Hand

Joined: Apr 29, 2008
Posts: 47
Hi friends,
Source: Whizlabs Final Exam
What is your design observation on the following code fragment -

I thought this was an example of Low Cohesion, but the right answer is Tight Coupling. Now,both sound right to me. Is there a reason why this isn't a good example of Low Cohesion?
Thanks,
Seema
Lakuma Yalamanchili
Greenhorn

Joined: Sep 24, 2008
Posts: 26
Coupling can be identified by how much change in another class would bring a change to this class. It should be as less as possible. Tight Coupling is kind of a bad design as you know! The Truck class in the code has two other classes present in it which kind of makes it dependable on those classes and they are not even declared private!

So tight coupling makes the right answer! Low cohesion is not the answer because, cohesion defines how specific is a class made to it's operation! If the class Truck performed the Driver and the Price class related operations it would have been low cohesion, but as seen in the code, Driver and Price have their own classes.

Hope I could drive the point. Please let me know if this is not clear! And please do correct me if you feel I have messed up something!

Regards,
Lakuma
Seema Gaurav
Ranch Hand

Joined: Apr 29, 2008
Posts: 47
Oh yes, Lakuma, you made it very clear. Looks like I was royally confused. You are right, the Truck class didn't have any of the Driver or Price classes behavior in it. I totally missed that point

Thanks to you, my fundas are in place now
Seema
Lakuma Yalamanchili
Greenhorn

Joined: Sep 24, 2008
Posts: 26
Good to know I was able to help!!

Good luck to you!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Low Cohesion or Tight Coupling?