• 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

Coupling Query

 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assertion : Class A uses public members exposed by class B and does no use Class B member variables ??

Query ? Can we say class A and Class B are tightly coupled ???

 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sahil Kapoor wrote:Assertion : Class A uses public members exposed by class B and does no use Class B member variables ??

Query ? Can we say class A and Class B are tightly coupled ???



I think, they are loosely coupled! Because, the Class A uses the public members and doesn't use it's member variables of Class B. Class B is well encapsulated.....
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Abhimaran

Pardon me if i am drifting away from Exam's objective.

But as soon as we start speaking class instead of type, we get hooked to that particular class. For loose coupling in pure sense, two objects should talk to each other over an abstraction, i.e. interface.

Please correct me if i am wrong.


 
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Himanshu Mall wrote:@Abhimaran

Pardon me if i am drifting away from Exam's objective.

But as soon as we start speaking class instead of type, we get hooked to that particular class. For loose coupling in pure sense, two objects should talk to each other over an abstraction, i.e. interface.

Please correct me if i am wrong.




Himanshu, I think you are right, because when I was doing some exercises from K&B Java 5 (chapter 2 - exercise 5) I found something that matches with what you said.
There is a question that calls for assertions that better points a loosely coupling situation.
There is an assertion that I thought that it was valid: "All classes attributes are private".
So, checking the answers that assertion was not valid. So, I can infer that only making instance variables private do not make a loosely coupling.

Considering all that, I think you are right when saying that for loose coupling we need to use abstraction (i.e. interface)

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in a class with private instance variables the interface we need to get loose coubling is the public getters and setters (public instance methods)
in Java class = type + interface
 
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic