源代码设计、实现、控制、两人合作

源代码:

public class CompanyArmy {

       public void sneakAttack() {

              System.out.println("我们知道如何偷袭敌人,保证完成任务");

       }

}

 

public interface Command {

       public abstract void execute();

}

 

public class ConcreteCommand implements Command{

       CompanyArmy army;

       ConcreteCommand(CompanyArmy army){

              this.army=army;

       }

       public void execute() {

              army.sneakAttack();

       }

}

 

public class ArmySuperior {

       Command command;

       public void setCommand(Command command) {

              this.command=command;

       }

       public void startExecuteCommand() {

              command.execute();

       }

}

 

public class Application {

       public static void main(String args[]) {

              CompanyArmy threecompany=new CompanyArmy();

              Command command=new ConcreteCommand(threecompany);

              ArmySuperior commander=new ArmySuperior();

              commander.setCommand(command);

              commander.startExecuteCommand();

       }

}

https://github.com/uonuo/practice

    我们两人分析好要做的程序后,需要开始设计代码。在设计代码前,我们应统一代码格式,不规范的代码格式会给两人互相阅读对方的代码带来困扰。编写好代码后,我们使用Junit进行测试。双方还互相审阅对方的代码,把所有问题与对方商量着解决,力求合作双方的意见达到一致,这样的及时交流有利于程序编写的高效率进行。

猜你喜欢

转载自blog.csdn.net/hsyoko/article/details/80114239