我得到了这组代码,需要提出改进代码内聚和类耦合的方法。但我认为这些类很好地解耦,因为看起来它们正在使用事件。就凝聚力而言,所有的 init() 调用都放在一起,对我来说一切都很好。
public class A
{
private C t;
private B g;
public static void main(String args[]) {
// Creates t and g.
t = new C();
t.init();
g = new B();
g.init();
g.start(this);
}
pubic void update (Event e)
{
// Performs updating of t based on event
}
}
public class C
{
public C() { ... }
public void init() { ... }
}
public class B
{
public B() { ... }
public void init() { ... }
public void start(A s) {
e = getNextEvent();
while (e. type != Quit)
if (e.type == updateB)
update(e) ;
else
s.update(e) ;
e = getNextEvent();
}
public void update(Event e) { ... }
}
}
还有办法提高类的内聚和耦合吗?对我来说看起来不错,但我想我错过了一些东西。
感谢您对此提出任何建议。