请问如何重构代码

miaozilong · · 677 次点击
``` func (this *Account) Push(money float64, note string) { var account Account account.accountType = "收入" account.money = money account.note = note account.balance += account.money accounts = append(accounts, account) } func (this *Account) Pull(money float64, note string) { var account Account account.accountType = "支出" account.money = money account.note = note account.balance -= account.money accounts = append(accounts, account) } ```
#2
更多评论
`` func (this *Account) Push(money float64, note string) { var account Account account.accountType = "收入" account.money = money account.note = note account.balance += account.money accounts = append(accounts, account) } func (this *Account) Pull(money float64, note string) { var account Account account.accountType = "支出" account.money = money account.note = note account.balance -= account.money accounts = append(accounts, account) }
#1
``` func (this *Item) transfer(accountType string, money float64, note string) { var account Item account.accountType = accountType account.money = money account.note = note balance += account.money account.balance = balance accounts = append(accounts, account) } func (this *Item) Push(money float64, note string) { this.transfer("存入", money, note) } func (this *Item) Pull(money float64, note string) { this.transfer("支出", -money, note) } ``` 这样应该可以的
#3