实验4:抽象工厂模式
本次实验属于模仿型实验,通过本次实验学生将掌握以下内容:
1、理解抽象工厂模式的动机,掌握该模式的结构;
2、能够利用抽象工厂模式解决实际问题。
[实验任务一]:人与肤色
使用抽象工厂模式,完成下述产品等级结构:
实验要求:
1. 画出对应的类图;
2. 提交源代码;
Java----------------------------------------------------------------------------
public interface EFactory
{
public Man produceMan();
public Woman produceWoman();
}
public class Yellow :public EFactory
{
public Man produceMan()
{
return new huangMan();
}
public Woman produceWoman()
{
return new huangWoman();
}
}
public class Black :public EFactory
{
public Man produceMan()
{
return new heiMan();
}
public Woman produceWoman()
{
return new heiWoman();
}
}
public class White :public EFactory
{
public Man produceMan()
{
return new baiMan();
}
public Woman produceWoman()
{
return new baiWoman();
}
}
public interface Man
{
public void play();
}
public interface Woman
{
public void play();
}
C++-----------------------------------------------------------------------------
public interface EFactory
{
public Man produceMan();
public Woman produceWoman();
}
public class Yellow :public EFactory
{
public Man produceMan()
{
return new huangMan();
}
public Woman produceWoman()
{
return new huangWoman();
}
}
public class Black :public EFactory
{
public Man produceMan()
{
return new heiMan();
}
public Woman produceWoman()
{
return new heiWoman();
}
}
public class White :public EFactory
{
public Man produceMan()
{
return new baiMan();
}
public Woman produceWoman()
{
return new baiWoman();
}
}
public interface Man
{
public void play();
}
public interface Woman
{
public void play();
}
3.注意编程规范。