• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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: 9697
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: 14283
321
  • 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
 
Slime does not pay. Always keep your tiny ad dry.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic