我正在尝试在我的开发中应用 MVC(没有任何框架),但我遇到了很多麻烦。第一个麻烦:M!您如何处理具有深层数据结构和多个“根元素”的复杂模型?
这是一个非常简单的例子。假设我们的模型只有两个“点”。哪个是最好的模型实现?
想法 n°1:使用一个入口点和吸气剂
import java.awt.Point;
public class TwoPointsA {
private final Point A = new Point();
private final Point B = new Point();
public Point getA() {
return this.A;
}
public Point getB() {
return this.B;
}
}
想法 2:使用一个入口点并委托方法
import java.awt.Point;
public class TwoPointsB {
private final Point A = new Point();
private final Point B = new Point();
public void translateA(final int dx, final int dy) {
this.A.translate(dx, dy);
}
public void translateB(final int dx, final int dy) {
this.B.translate(dx, dy);
}
}
想法 3:使用多个入口点和吸气剂
import java.awt.Point;
public class TwoPointsC {
public enum Points {
A, B;
private final Point value = new Point();
public Point get() {
return this.value;
}
}
}
想法 4:使用多个入口点和委托方法
import java.awt.Point;
public class TwoPointsD {
public enum Points {
A, B;
private final Point value = new Point();
public void translate(final int dx, final int dy) {
this.value.translate(dx, dy);
}
}
}