限制性API(对客户端用户施加限制)
我正在编写一个 API,并遇到了以下模式:
我的 API 将强制客户端用户执行他/她所编写的内容。该代码必须通过使用不同的凭据登录/注销来测试门户上的 x 个站点。我不能指望另一个开发人员会编写他/她自己的登录代码(这将是通用代码),因此我编写了一个带有私有构造函数的抽象类来实现登录和退出方法以及主要测试方法(用户必须覆盖该方法才能填写0)。
我还没有见过施加这样的限制的API,但这是团队的API。
我的方向正确吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是封装的要点。作为开发人员,您决定在其他程序员面前隐藏什么以及他们能够调用哪些方法。我看你只是想确保这是一个好的决定,嗯,确实如此,它是 OOP 的核心概念之一。
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.