About Question enthuware.ocajp.i.v7.2.1213 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
The_Nick

About Question enthuware.ocajp.i.v7.2.1213 :

Post by The_Nick »

Hi
What is the exact difference between coupling and encapsulation?
Thanks a lot in advance.

The_Nick

Online
admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1213 :

Post by admin »

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.


hamzaBlm
Posts: 18
Joined: Thu May 23, 2019 11:58 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1213 :

Post by hamzaBlm »

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?

Online
admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1213 :

Post by admin »

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

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests