Matloob Hussain wrote:As I know, Car has private instance method
If the Car's constructor changes or someone decides that you can no longer change the Car color (setColor is made private), you are forced to update this code of the Driver class.
Matloob Hussain wrote:After updating new code, if we made any changes in Car class. Does it not force to update the code of Driver class?
In SCJP Sun Certified Programmer for Java 6 Study Guide by Katherine Sierra and Bert Bates (K&B):
Loose coupling is the desirable state of having classes that are well encapsulated, minimize references to each other and limit the breadth of API usage.
Matloob wrote:"minimize references to each other", "limit the breadth of API usage"
Matloob Hussain wrote:
As I understand: Please correct me if I am wrong or if I am missing something.
1-Only one class is involved in encapsulation.
2-If instance variables are private and getter and setter are public then it is "well ecncapsulated".
3-If instance variables, getter and setter are public then it is "poor encapsulated".
1- More than one classes are involved in coupling.
2- These classes must be well encapsulated.
3- If classes A.P.I are accessed by using the reference of interface (which makes independent) then it means, It has loose coupling.
4- If classes A.P.I are accessed by using the reference of concrete class (which makes dependent) then it means, It has tight coupling.
So to acheive loose coupling state, it need following steps:
1- make it well encapsulated
2- implements interface
3- use the interface reference to access classes A.P.I