Viewing a single comment thread. View all comments

Regayov t1_j9zu6gl wrote

By encapsulating your code you are defining and separating the external interface from the internal implementation. By doing that the internal implementation can change without breaking everyone who used your components. Without it anyone who uses your components could come to rely on any method or variable you used. If a better implementation comes around and those methods or variables are removed then their code will break.

Similarly if your component is complex, say with lots of concurrency/threads, then leaving internal methods or variables externally accessible can cause all sorts of problems. External components could access those internal structures directly, potentially bypassing any protections you established.

1