This week's book giveaway is in the Android forum.
We're giving away four copies of Learning Java by Building Android Games and have Jean-Marcel Belmont on-line!
See this thread for details.
Win a copy of Learning Java by Building Android Games this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!