Restrictive API (imposing limits on the client user)
-
24-09-2019 - |
Question
I am writing an API and have come across the following pattern:
My API will force the client user in what he/she writes. The code must test x number of sites on a portal by logging in/out with different credentials. I cannot rely on chance that another developer will write his/her own login code (and this is going to be common code) so I have written an abstract class with a private constructor to implement the logging in and out methods, and the main test method (which the user will have to override to fill in0.
I have not seen an API which imposes restrictions like this but then this is an API for the team.
Am I on the right track with this?
Solution
This is the point of encapsulation. You as a developer decide what to hide before other programmers and which methods they are able to call. I see you just want to make sure this is a good decision, well, it is, it is one of the core concepts of OOP.