• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

OO Concepts - Encapsulation, Cohesion, Coupling

 
Ranch Hand
Posts: 125
Postgres Database BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dieter Quickfend wrote:You're the one who asked for an example of both at the same time, perhaps it's convoluted, but I'm not planning on writing a novel.

More importantly, (and that was the purpose) it shows that bad encapsulation does not necessarily mean tight coupling. If you've got public variables that nobody uses, you've got bad encapsulation and loose coupling.

So in most cases, bad encapsulation enables tight coupling, but not in all cases, it is not a given.

And it is tight coupling that directly represents the problem here, so the solution should definitely be tight coupling.



its all a mater of definition.
By strong encapsulation we mean the "allowance" or "enforcement"? (EXISTS vs FORALL)
By loose coupling we mean the "allowance" or "enforcement"?(EXISTS vs FORALL)

If two perfectly encapsulated classes use one another directly (without the use of polymorphism based on interfaces) are
supposed to be tightly or loosely coupled?

After we answer all those philosophical questions (which should have been answered in the SB textbook either way) then we can start answering other questions.
 
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dieter Quickfend wrote:So the solution should definitely be tight coupling.


Ikpefua wrote:


Hello Dieter do you mean solution to my question or solution to your code? because the problem with your code as it stands is poor encapsulation(public instance variables - tight coupling or vulnerable to tight coupling depending on the user), hence good encapsulation(private instance variables - loose coupling NO vulnerability) takes care of that, dont you think so?.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Same as Nidhi, I keep on tripping upon questions of Encapsulations,Coupling and Cohesion. Being more specific I am not able to identify the examples of tight or loose coupling. I understand the concept that "coupling is the degree that one class knows about another."
Here is one I failed to answer correctly in the K&B MasterExam:

Given a class House, which are true? [choose all the apply.]

A. House has-a Roof would be considered tight coupling.
B. A turnOnStereo() method would NOT be considered cohesive.
C. House is-a Dwelling would be considered good encapsulation.
D. House has-a Door would be considered low coupling.
E. A getAddress() method would NOT be considered cohesive.

I am correctly able to identify that C and E are wrong and B is correct. I am confused about A and D. Can anyone please explain?
Thanks
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

Overall good discussion.

It seems however that a few times a little anger flared up. Try to remember a few things about the context of this discussion, or any discussion in these forums:

- it's illegal to discuss real exam questions.
- any questions discussed here are either from mock exams, or they are necessarily imprecise

If you're discussing a mock question, then it's ESSENTIAL that you display the exact question, in it's entirety - and mention the author.

Making good questions requires extremely precise wording, often changing a single word can radically alter the validity of a question. Of course mock question writers are human, so errors do occur, but the default orientation should be that the question is correct. I'd say that 9 times out of 10, when people are discussing mock exam questions, the question is correct.

That leaves the 1 in 10 - if, after a question has been discussed, an error is found, that's good news! The author can fix the error, and everyone in the discussion has demonstrated a certain mastery of the topic - which is the goal after all.

Chill out, have fun.

Bert
 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic