<?php/*** Created by PhpStorm.* User: ZenGo* Date: 2017年2月9日* Time: 23:50* 简单工厂设计模式*/namespace DesignPattern\FactorPattern;interface Shape{public function draw();}class Rectangle implements Shape{public function draw(){// TODO: Implement draw() method.print_r("Inside Rectangle::draw() method.");}}class Square implements Shape{public function draw(){// TODO: Implement draw() method.print_r("Inside Square::draw() method.");}}class Circle implements Shape{public function draw(){// TODO: Implement draw() method.print_r("Inside Circle::draw() method.");}}class ShapeFactory{public function getShape($shapeType){if ($shapeType == null) {return null;}$type = strtoupper($shapeType);if ($type == "CIRCLE") {return new Circle();} else if ($type == "RECTANGLE") {return new Rectangle();} else if ($type == "SQUARE") {return new Square();}return null;}}$type = 'RECTANGLE';$shapeFac = new ShapeFactory();if ($shapeFac->getShape($type)) {$shapeFac->getShape($type)->draw();} else {print_r("类型不存在");}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。