• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

coupling improvement

 
Greenhorn
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??


thnks
 
Marshal
Posts: 65365
248
  • 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?
 
Run away! Run away! Here, take this tiny ad with you:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!