views:

28

answers:

1

Hi,

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?

A: 

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.

pajton
Thanks for the feedback. Yeah I was not sure of whether the locked down approach was bad. The usability and documentation of the API is unaffected, however, so should be a good system.
dotnetdev
Also, I guess it is for me to decide whether this is a good decision in relation to the business circumstances.
dotnetdev