jeudi 1 août 2019

Is encapsulation an overkill for non-library code and/or open source?

Encapsulation can be very useful when you are developing a library/api that will be used by 3rd parties, as you only want to expose that which is needed.

But when you have an open source library, or an internal code base develop by a product team, what is the value of encapsulation?

I can only think it's useful for 2 reasons:

1) Preventing a junior developer from misusing internal methods/variables from a class? Although this could be achieved by good documentation/comments/training on how to use the code.

2) Providing intent and implicit documentation. By having only a handful of public methods, it's easy for new comers to understand what is the interface of that class, and potentially means they don't need to understand all the implementation details. If all the methods were public it'd be hard to understand the interface.

Other than these 2, what are other benefits when it comes to open source code or internal code bases?

Aucun commentaire:

Enregistrer un commentaire