• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to promote better coupling?  RSS feed

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a mock exam question on Java.Inquisition.


Given these two classes and that you want to promote better coupling between them. What changes are required to achieve good coupling ? Also given that the int variable main is to be used when initializing coupler�s variables.


My answer was 3.
because on line 3, coupler class is using the Instance variable of test class, which makes them tightly coupled.

Correct answer is 2.

Can soem one explain where I am going wrong?
 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Originally posted by Varalakshmi Ramanarayan:
This is a mock exam question on Java.Inquisition.


Given these two classes and that you want to promote better coupling between them. What changes are required to achieve good coupling ? Also given that the int variable main is to be used when initializing coupler�s variables.


My answer was 3.
because on line 3, coupler class is using the Instance variable of test class, which makes them tightly coupled.

Correct answer is 2.

Can soem one explain where I am going wrong?



My answer would be 3 also.
I'm not sure I understand entirely/correctly their option 2. Line#2 is definitely bad coupling.
Line #2 is so bad, it instantiate the class containing the main method and directly access its member.

I would consider this being an error and move on Unless someone has a better idea.
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some please provide a good link for coupling and cohesion with examples.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy ranchers,

option 3 is not correct. The method's name is "getMain" and not "getPain".
With line 1 changed to
c.setMain(main);
it would be less coupled.

You have a situation then where one object (coupler) returns an value(main, an int) of another object (test).
This value is not necessarily the pain-value of coupler. coupler is instantiated with this value, but after some other action (from some third class that uses test) the test-main value may have changed.


Yours,
Bu.
 
Varalakshmi Ramanarayan
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks All of you for replying..
n Thanks Burkhard.. Your post cleared my doubt...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!