通过各位的解答,写出下面代码:
Decorator:
public class Client
{
public Client()
{
}
public static void main(String args[])
{
Worker james = new James();
SoldierDecorator jamesSoldier = new SoldierDecorator(james);
System.out.println(jamesSoldier.getJob());
}
}
interface Worker
{
public String getJob();
}
class James
implements Worker
{
public String getJob()
{
return "打工的";
}
}
class SoldierDecorator implements Worker
{
private Worker man;
public SoldierDecorator(Worker man)
{
this.man = man;
}
public String getJob()
{
return "在部队" + this.man.getJob();
}
}
class DeveloperDecorator implements Worker
{
private Worker man;
public DeveloperDecorator(Worker man)
{
this.man = man;
}
public String getJob()
{
return "在软件公司" +this.man.getJob();
}
}