| Author |
Coupling Query
|
Sahil Kapoor
Ranch Hand
Joined: Sep 12, 2009
Posts: 316
|
|
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 ???
|
SCJP 6.0 96%
(Connecting the Dots ....)
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
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.....
|
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
|
 |
Himanshu Mall
Greenhorn
Joined: Jun 28, 2010
Posts: 22
|
|
@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.
|
Regards
Himanshu Mall
@mall.himanshu84@gmail.com
|
 |
Adolfo Eloy
Ranch Hand
Joined: Mar 21, 2009
Posts: 144
|
|
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)
|
Adolfo Eloy
Software Developer
OCPJP 6
|
 |
Imad Aydarooos
Ranch Hand
Joined: Nov 02, 2010
Posts: 87
|
|
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
|
love demgracy, knowledge demogracy, open source and Java - OCPJP 76%
|
 |
 |
|
|
subject: Coupling Query
|
|
|