return new Curry(); break; // 三明治廚師 // 三明治廚師 case 'sandwich': return new Sandwich(); break; } } } /** * 餐廳 */ class Restaurant { public function order($meal) { // 透過廚師工廠,聘請會煮這道餐點的廚師 $chef = ChefFactory::hireChef($meal); // 烹煮食物 $chef->prepareIngredient(); $chef->cooking(); $chef->serve(); } } // 到餐廳用餐 $restaurant = new Restaurant(); // 點餐:咖哩 $restaurant->order('curry'); // 點餐:三明治 $restaurant->order('sandwich');