• 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

Can u explain low coupling

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is Question 5 in Chapter 2-Self Test of K&B. It's like this:


The correct answers are E, F..

Can you explain why other options are WRONG in detail and throw some more light on loose and tight coupling, as i'm not fully satisfied with the explanation given in K & B.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy!

Welcome to the Ranch, Palla!






I'll try to explain a bit:

A. The attributes of the class are all private.
Doesn't have to do with low coupling but with encapsulation.


B. The class refers to a small number of other objects.
Generally, a class should not have too much objects.
But having only a small number of other objects alone is not sufficient for low coupling.
In the K&B there was an example of only two classes having each other and they were heavily interacting together back and forth, so they were tightly coupled which is bad.

Regarding the opposite: A lot of other objects, is this high coupling?
No, a class can have a lot of objects and still be highly coupled. if a class has to perform a complicated task, it may need all these objects. As long as all these don't know too much of the class that has them, the coupling could be still low.


C. The object contains only a small number of variables.
Same as b. Having a variable is just the same as referring to an object (plus referring to primitive types, but these aren't subjects of coupling because they cannot react back to the class that has them).


D. The object is referred to using an anonymous variable, not directly.
"Anonymous variables" simply do not exist, so D is false as well.


E. The reference variable is declared for an interface type, not a class. The interface provides a small number of methods.
Generally you can expect that an interface has less methods than a class implementing it (because the class would have the interface's method(s) plus its own).
Limiting the breadth of API usage is also an indication for low coupling. So E is true.


F. It is unlikely that changes made to one class will require any changes in another.
Yes, true, unlike in the "bad example" in the K&B book.
Low coupling: Class A has-a B-object and performs some changes on this object. System ready (in italian: Basta.).
Tight coupling (bad): Class A has a B-object. Class B changes something in B and B reacts in changing something in the A objects as a reaction of this. Complicated and error prone.



Generally, these more abstract subjects (encapsulation, cohesion and coupling) are not as easy to understand (and explain) as more Prince of Denmark like "to compile or not to compile" facts to learn.

So be invited to discuss this, I'm certainly not a Guru in this field...


Yours,
Bu.
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

E. The reference variable is declared for an interface type, not a class. The interface provides a
small number of methods.



I'm confused a little about what's being asked in the first part of this question...

*What* reference variable are they referring to? How and where is it declared?

This is one of the many vague questions that's got me miffed a bit about getting certified.

Aloha,
Doug

-- Nothing is impossible if I'mPossible.
[ October 17, 2007: Message edited by: Doug Slattery ]
 
palla sridhar
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Hassel, for your explanation. But still i was left with one more doubt regarding variables. For option A,

The attributes of the class are all private.

the explanation given in K&B is given as follows.

Variables (attributes) in a class should usually be private, but this describes encapsulation, rather than low coupling. Of course, good encapsulation tends to reduce coupling as a consequence.



So, if encapsulation results in low coupling, can't option A be the right answer ?
 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic