• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question regarding coupling and cohesion

 
Greenhorn
Posts: 20
Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given a class House which are true?

a. House has a roof may be considered tight coupling.
b. a turnOnStrereo() may be considered cohesive.
c. House-is-a-Dwelling is considered good encapsulation.
d. House-has-a-door would be considered loose coupling.
e. a getAddress() method would not be considered cohesive.

Correct answers are (b.) and (d.). Please explain how they are correct and also the reason why others are incorrect.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pritha, welcome to CodeRanch.

Did you copy the question correctly? I believe option B that you've mentioned is incorrect. I found an old thread on the same question. You might find the answers there helpful. I personally don't like this type of questions, they are too vague for my liking
 
Saloon Keeper
Posts: 15445
362
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch Pritha!

I would also reason that B is incorrect. Cohesion has to do with what responsibilities a class has.

a. is incorrect because a House logically has-a Roof. If a Roof also knew about what House it belongs to, that would be tight coupling.
b. is incorrect because a House may have a Stereo, but a House shouldn't be responsible for turning a Stereo on. A Stereo should be responsible for turning itself on.
c. is incorrect because inheritance has nothing to do with encapsulation.
d. is correct for the same reason a. is incorrect. A house needs a door. If the door needed a house, it would be tightly coupled.
e. is incorrect because a House has an address, and getting an address for a House is part of the House's responsibilities.
 
Pritha Banerjee
Greenhorn
Posts: 20
Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you I got it
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic