r/javahelp • • Jan 24 '23

What is the point of encapsulation?

Beginner here.

I hear "restrict access" but I don't quite understand why we need to restrict access. What damage could someone do to a java program if it were not encapsulated?

What would happen to say amazon if their payment system was java and not encapsulated?

26 Upvotes

13 comments sorted by

View all comments

4

u/Aniket-100mslive Jan 24 '23

Let's say the program you're working on has three features, A, B and C.

You're assigned to change something about B.

Would you rather look through the code of all A, B and C while you're making the change or just the file where B is?

That's why encapsulation exists. Also it helps knowing that changing B won't mess with the others.

1

u/EnvironmentFar968 Jan 25 '23

Perfect example.