简体   繁体   English

如何防止开发人员使用危险的方法

[英]How to prevent developers from use risky methods

I'm looking for a way to prevent developers from using some methods that are causing instability (Performance) issues for the site; 我正在寻找一种方法,以防止开发人员使用某些导致网站不稳定(性能)问题的方法。 for example, I have a method fetches the information from the database (eg getData(String id) ), and another method fetches the information form the in-memory cache (eg getCachedData(String id) ). 例如,我有一个方法从数据库中获取信息(例如getData(String id) ),另一个方法是从内存缓存中获取信息(例如getCachedData(String id) )。 The getData(String id) method is used in getCachedData(String id) if and only if we have a cache-miss. 当且仅当我们有cache-miss时,才在getCachedData(String id)使用getData(String id)方法。 How can I prevent developers from using getData(String id) method? 如何防止开发人员使用getData(String id)方法? in other words, I need to force developers to use getCachedData(String id) always. 换句话说,我需要强制开发人员始终使用getCachedData(String id)

Please note that the access modifiers (private, protected, etc.), code design, or java docs are not really preventing developers. 请注意,访问修饰符(私有,受保护等),代码设计或Java文档并not真正阻止开发人员。 Do we have a final solution for this issue? 我们是否有针对此问题的最终解决方案?

  1. Document the methods well, and explain which is preferable. 记录好方法,并说明哪种方法更好。
  2. Write a custom annotation to produce a compilation warning. 编写自定义注释以产生编译警告。
  3. Decorate the class, so getData would return getCachedData . 装饰类,因此getData将返回getCachedData

The interface is pretty unclear, there shouldn't be a method getCachedData at all. 接口非常不清楚,根本不应该有方法getCachedData getData returns either the cached data or newly-fetched data. getData返回缓存的数据或新获取的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM