Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Coupling Query

 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • 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 ???

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • 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.....
 
Himanshu Mall
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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.


 
Adolfo Eloy
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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)

 
Imad Aydarooos
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic