1类图
2c++例子
; { : string getName(); ~Fruit(){ } }; { : string getName(); ~Food(){ } }; { : Fruit createFruit(); Food createFood(); ~FruitFactory(){} }; : Fruit{ : string getName(){ ; } ~BeijinApple(){ } }; : Fruit{ : string getName(){ ; } ~ZhejiangApple(){ } }; : Food{ : string getName(){ ; } ~BeijinNoodle(){ } }; : Food{ : string getName(){ ; } ~ZhejiangRice(){ } }; : FruitFactory{ : Fruit createFruit(){ BeijinApple; } Food createFood(){ BeijinNoodle; } ~NorthFactory(){} }; : FruitFactory{ : Fruit createFruit(){ ZhejiangApple; } Food createFood(){ ZhejiangRice; } ~SouthFactory(){} }; (){ FruitFactory factory NorthFactory; Fruit fruitfactorycreateFruit(); coutfruitgetName()endl; fruit; Food foodfactorycreateFood(); coutfruitgetName()endl; food; factory; factory SouthFactory; fruitfactorycreateFruit(); coutfruitgetName()endl; fruit; foodfactorycreateFood(); coutfruitgetName()endl; food; factory; ; }