【发布时间】:2020-01-15 19:37:09
【问题描述】:
我正在使用 Java 开发 android,并且正在实现 Model-View-Presenter 架构。玩家可以玩两种类型的游戏:
- 游戏A
- 游戏 B
这两款游戏非常相似,但都有各自的 .class 文件和(例如 GameA.class 和 GameB.class)。
在这两种情况下,它们各自的演示者都是相同的,唯一改变的是模型类的实例化和声明。例如:
GameAPresenter.class:
class GameAPresenter{
private GameA game;
// other stuff here that happens in both presenters
GameAPresenter(int par1, int par2){
this.game = new GameA(par1, par2);
//other stuff here that happens in both presenters
}
}
GameBPresenter.class:
class GameBPresenter{
private GameB game;
// other stuff here that happens in both presenters
GameBPresenter(int par1, int par2){
this.game = new GameB(par1, par2);
//other stuff here that happens in both presenters
}
}
有什么方法可以完全避免重复代码,由单行 cmets 模拟? 如果我可以让两个模型共享一个演示者,则奖励。
【问题讨论】:
-
关于代码审查的问题应该在Code Review提出
标签: java android class duplicates mvp