最善を尽くして説明しようと思います。
私はPlayFramework2を使用しており、多くのCRUDアクションを実行します。それらのいくつかは同一であるため、KISSとDRYを実行したいので、最初は、、、、およびメソッドを含む抽象クラスをジェネリックオブジェクトで考え、list
使用するオブジェクトを指定してこのクラスを拡張しました(モデル& 形) :details
create
update
delete
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
}
}
そして、CRUDを使用するクラス:
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
}
}
これは、静的なコンテキストにいない場合に機能します。
しかし、それが事実なので、どうすればよいですか?