Hi
What is the exact difference between coupling and encapsulation?
Thanks a lot in advance.
The_Nick
About Question enthuware.ocajp.i.v7.2.1213 :
Moderator: admin
Online
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1213 :
Coupling means how interconnected classes are. Tight coupling means that the classes know a lot of internal details such as instance fields and methods (which are not exposed by an interface) of each other.
Encapsulation basically hides the instance variables by making them private. This reduces coupling because other classes cannot directly access those fields.
Encapsulation basically hides the instance variables by making them private. This reduces coupling because other classes cannot directly access those fields.
-
- Posts: 15
- Joined: Fri Jul 12, 2013 12:34 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1213 :
Found another nice explanation:
http://www.coderanch.com/t/411693/java/ ... esion-java
http://www.coderanch.com/t/411693/java/ ... esion-java
-
- Posts: 18
- Joined: Thu May 23, 2019 11:58 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1213 :
I understand than Encapsulation does its job to reduce coupling between classes by hiding internal details.
My question is:
Can we reduce coupling by following the principle of "program to interfaces not to implementations"?
I think by following the principle we can have low coupling because now the classes depend on the interface, not the implementation. am I correct?
My question is:
Can we reduce coupling by following the principle of "program to interfaces not to implementations"?
I think by following the principle we can have low coupling because now the classes depend on the interface, not the implementation. am I correct?
Online
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1213 :
The measure of these parameters is quite subjective. So, yes, one could argue that. But it would not be too beneficial to discuss this here as we are focused more on the certification. You will get better answer for it on sites such as coderanch.com
Who is online
Users browsing this forum: No registered users and 4 guests