我会尽力解释
我使用 Play Forum 2, 我会做很多 CRUD 动作。 其中一些动作将会是身份识别的, 所以我喜欢 KISS 和 DRY, 所以在一开始我想到一个抽象的分类, 包含 < code> list code > 、 < code > details code > 、 < code > create code > 、 < code> update code > 和 < code> < deletete code> 方法, 带有通用对象, 并且通过指定要使用的对象来扩展这个类别( model & amp; 表) :
public abstract class CrudController extends Controller {
protected static Model.Finder<Long, Model> finder = null;
protected static Form<Model> form = null;
public static Result list() {
// some code here
}
public static Result details(Long id) {
// some code here
}
public static Result create() {
// some code here
}
public static Result update(Long id) {
// some code here
}
public static Result delete(Long id) {
// some code here
}
}
以及使用CROUD的阶级:
public class Cities extends CrudController {
protected static Model.Finder<Long, City> finder = City.find;
protected static Form<City> form = form(City.class);
// I can override a method in order to change it s behavior :
public static Result list() {
// some different code here, like adding some where condition
}
}
如果我不是在一成不变的情况下这样做,将会有效。
但既然如此,我该怎么做?