如何设计类的方法
确定一个类之后,应该如何设计它的方法?或者说,某一个方法应该属于哪个类?比如:
the client deposits money into the account.那么deposits方法应该是属于client还是account?
有没有什么方法来判断?
------解决方案--------------------deposits方法应该属于account,而client会调用这个方法。
感觉楼主对面向对象理解不够深刻,建议再读一些相关的书籍。
------解决方案--------------------按照一般的理解,client 当中会这样写:
public void deposite(Money money) {
this.account.deposite(money);
}
所以是两个都有。