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
Joined: Sep 24, 2008
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!
Joined: Apr 29, 2008
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