Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding coupling between classes

 
Vinayagar Karpagam
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I came across a question from the K&B master exam which is as follows :

which of the following has the tightest coupling?
new BioDiesel(new Integer(10))
new BioDiesel(new String("Hello"))
new BioDiesel(new Viscosity())

I cant find any difference between the options regarding coupling..

Can anyone help me find the answer?

Thanks in advance.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class BioDiesel in turn depends on the class Viscosity() for it to be initialized. So you have to know if statement new Viscosity() is legal, or may be the class Viscosity uses a getInstance method to pass a new instance to you, or may be the class Viscosity uses a getViscosityInstance to pass a new instance, or may be... well you get the picture.
 
Vinayagar Karpagam
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answer.

I'm getting the question now..

Since Integer & String come from java.lang,

there is no necessity of extra knowledge about them from BioDiesel.

Here, since Viscosity is a user class, the class BioDiesel is coupled
tightly.

But, considering classes String & Integer as typical modules in a
system, the class BioDiesel is said to be tightly coupled to the String,
Integer classes. Am i right?
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your class is a user class then yes the coupling is tighter. The real exam will not ask you - what if String is a module outside the java.lang package. In fact the coupling question that i encountered on the exam was programmatic and a drag and drop. Yikes ! However they are easy to answer. Like the Kathy and Bert book mentions - the question will be direct and simple.
 
Vinayagar Karpagam
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, John Meyers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic