package builder;
class Commodity {
String commodity ="";
public Commodity(Part parta,Part partb,Part partc)
{
this.commodity=parta.part+"\n";
this.commodity+=partb.part+"\n";
this.commodity+=partc.part+"\n";
System.out.println("我的电脑配置为"+commodity);
}
}
class Part
{
String part="";
public Part(String part)
{
this.part=part;
}
}
interface Computer
{
void buildParta();
void buildPartb();
void buildPartc();
Commodity getCommodity();
}
//组装师
class Assember
{
private Computer computer;
public Assember(Computer computer)
{
this.computer=computer;
}
public void construct()
{
computer.buildParta();
computer.buildPartb();
computer.buildPartc();
}
}
//我的电脑
class MyComputer implements Computer
{
Part parta,partb,partc;
public void buildParta()
{
parta=new Part("P4 2.8 CPU");
}
public void buildPartb()
{
partb=new Part("华硕主版");
}
public void buildPartc()
{
partc=new Part("LG显示器");
}
public Commodity getCommodity()
{
Commodity mycomputer=new Commodity(parta,partb,partc);
return mycomputer;
}
}
public class MyComputerTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MyComputer mycomputer=new MyComputer();
Assember assember=new Assember(mycomputer);
assember.construct();
Commodity mycommodity=mycomputer.getCommodity();
}
}