GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regarding coupling between classes 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 "Regarding coupling between classes" Watch "Regarding coupling between classes" New topic
Author

Regarding coupling between classes

Vinayagar Karpagam
Ranch Hand

Joined: Apr 09, 2006
Posts: 72
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

Joined: Feb 24, 2006
Posts: 6661
    
    5

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.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Vinayagar Karpagam
Ranch Hand

Joined: Apr 09, 2006
Posts: 72
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

Joined: Feb 24, 2006
Posts: 6661
    
    5

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

Joined: Apr 09, 2006
Posts: 72
Thanks a lot, John Meyers.
 
GeeCON Prague 2014
 
subject: Regarding coupling between classes