薪水支付案例(3)

删除雇员

下面给出删除雇员操作的静态和动态模型,删除雇员也是采用典型的COMMAND模式实现

删除雇员静态图:
这里写图片描述
删除雇员时序图:
这里写图片描述

下面给出部分代码,也是从测试代码开始:

DeleteEmployeeTransactionTest

package salary;

import implement.database.PayrollDatabase;
import implement.entity.Employee;
import implement.transaction.AddSalariedEmployee;
import implement.transaction.DeleteEmployeeTransaction;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertNull;
/**
 * 删除雇员
 * Created by ZD on 2017/10/24.
 */
public class DeleteEmployeeTransactionTest {
    PayrollDatabase payrollDatabase = PayrollDatabase.getPayrollDatabase();

    @Test
    public void testDeleteEmployee(){
        long id = 4;
        String name = "Bob4";
        String address = "Bob4.home";
        double monthlyPay = 1000;
        AddSalariedEmployee addSalariedEmployee = new AddSalariedEmployee(id,name,address,monthlyPay);
        addSalariedEmployee.execute();
        Employee e = payrollDatabase.getEmployeeById(id);
        //assertEquals(e,addSalariedEmployee);
        DeleteEmployeeTransaction deleteEmployeeTransaction = new DeleteEmployeeTransaction(id);
        deleteEmployeeTransaction.execute();
        assertNull(payrollDatabase.getEmployeeById(id));
    }
}

DeleteEmployeeTransaction

package implement.transaction;

import implement.database.PayrollDatabase;
/**
 * Created by ZD on 2017/10/24.
 */
public class DeleteEmployeeTransaction implements Transaction {
    private long id;
    public DeleteEmployeeTransaction(){}
    public DeleteEmployeeTransaction(long id){
        this.id = id;
    }
    public void execute() {
        PayrollDatabase.getPayrollDatabase().deleteEmployeeById(id);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值