Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

coupling improvement

Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you improve the coupling between these classes ?

1.) Mark int x=5 private and provide accessor fields to it

2.) Mark the variable z private

3.) Pass only the value of x instead of Main to quacker().

4.) Provide getters and setters for the variable z

5.) Remove IS A relation ship of Main with Duck

Answer: (1),(3)
The above code is from CertPal mock exams
To increase coupling one class shouldn't know
about other class anything other than API
so (1) is correct as it restricts access of field of Main by Duck
so here I wounder why (2),(4),5) isn't correct and why (3) is correct
and also if we remove Is a Relationship then
Main and Duck loosly coupled in a better way perhaps as they can't know anything
about each other..

Also tell me when any class with strong encapsulation has tight coupling with other classes
is it possible that 2 class have strong encapsulation and tight coupling??

Posts: 69420
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing I would suggest is correct the indentation. Exam code often has incorrect indentation and it catches a lot of people out.
I think that 1 is incorrect (or partially incorrect); it says make x private and provide accessor methods. You should definitely make x private, but there already is an accessor method.
Yes, z should be private, even though it has no effect on the program shown at present.
3 means to change the parameter to take an int because it only requires an int. Yes, that would improve the coupling.
4 would be a good idea, but like 2 would have no effect.
I can see no point in the inheritance; I think that is simply put in to confuse you.

Please, everybody else, comment on this thread. I think those are poor questions; does anybody else know this book/website?
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic