simple -- abstract
<?php
abstract class Operation {
protected $_NumberA = 0;
protected $_NumberB = 0;
protected $_Result = 0; public function __construct($A, $B){
$this->_NumberA = $A;
$this->_NumberB = $B;
} public function clearResult(){
$this->_Result = 0;
} abstract protected function getResult(); }
class OperationAdd extends Operation { public function getResult(){
$this->_Result = $this->_NumberA + $this->_NumberB;
return $this->_Result;
} }
class OperationSub extends Operation { public function getResult(){
$this->_Result = $this->_NumberA - $this->_NumberB;
return $this->_Result;
}
}
class OperationFactory { //创建保存实例的静态成员变量
private static $obj; //创建访问实例的公共的静态方法
public static function CreateOperation($type, $A, $B){
switch($type) {
case '+':
self::$obj = new OperationAdd($A,$B);
break;
case '-':
self::$obj = new OperationSub($A,$B);
break;
}
return self::$obj;
}
}
$obj = OperationFactory::CreateOperation('-', 5, 6);
echo $obj->getResult();
simple -- abstract的更多相关文章
- UVa 101 - The Blocks Problem(积木问题,指令操作)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- ACM题目————The Blocks Problem
代码参考:http://www.hankcs.com/program/uva-q101-the-blocks-problem.html Description Background Many area ...
- The Blocks Problem
Description Many areas of Computer Science use simple, abstract domains for both analytical and empi ...
- POJ 1208 The Blocks Problem
The Blocks Problem Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5397 Accepted: 231 ...
- The Blocks Problem(vector)
题目链接:http://poj.org/problem?id=1208 The Blocks Problem Time Limit: 1000MS Memory Limit: 10000K Tot ...
- JDK8漫谈——代码更优雅
简介 lambda表达式,又称闭包(Closure)或称匿名方法(anonymous method).将Lambda表达式引入JAVA中的动机源于一个叫"行为参数"的模式.这种模式 ...
- Winter-2-STL-D The Blocks Problem 解题报告及测试数据
Time Limit:3000MS Memory Limit:0KB Description Background Many areas of Computer Science use sim ...
- 4.3 Writing a Grammar
4.3 Writing a Grammar Grammars are capable of describing most, but not all, of the syntax of program ...
- EOJ 1501/UVa The Blocks Problem
Many areas of Computer Science use simple, abstract domains for both analytical and empirical studie ...
随机推荐
- DNS 取得授权
1.阿里云上cnroot.cn申请DNS解析服务器 也就是cnroot.cn下的子域名都从这个DNS上获取. 如www.cnroot.cn 如 handle.cnroot.cn 2.vi /home/ ...
- Shell脚本之:退出循环
Shell也使用 break 和 continue 来跳出循环. break命令 下面的例子中,脚本进入死循环直至用户输入数字大于5,使用break跳出这个循环. #!/bin/bash while ...
- sqlplus登入和plsql登入的差别
以下是两种登入方式的截图.用sqlplus登入须要输入主机字: 假设是用本机的SQL*Plus连接本机的数据库.则"主机字符串"能够为空. 假设是从远程连接xp的oracle数据库 ...
- Eclipse 经常使用快捷键
一.File 二.Edit Ctrl + 1 有益写错,让编辑器提醒改动 三.Refactor 抽取为全局变量 Refactor - Convert Local Variable to Field ...
- 莫小安 CentOS7使用firewalld打开关闭防火墙与端口
1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld 停止: systemctl disab ...
- Junit内部解密之三: 单元测试用例运行的全过程
转自:http://blog.sina.com.cn/s/blog_6cf812be0100x8sb.html 我们以一个非常简单的TestCalculator类为例,只有一个测试方法: Public ...
- oracle复合索引的选择和使用
声明:虽然题目是Oracle.但同样适合MySQL InnoDB索引 在大多数情况下.复合索引比单字段索引好 很多系统就是靠新建一些合适的复合索引.使效率大幅度提高 ...
- [译]GLUT教程 - 交换菜单
Lighthouse3d.com >> GLUT Tutorial >> Pop-up Menus >> Swapping Menus GLUT甚至可以在应用程序过 ...
- websocket通讯协议(10版本)简介
前言: 工作中用到了websocket 协议10版本的,英文的协议请看这里: http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotoc ...
- Selenium 应用 WebDriverWait 和 expected_conditions(待验证)
收藏在我的收藏看不到,只能copy了,转载至http://www.cnblogs.com/yicaifeitian/p/4749149.html 哈哈,我始终相信贴出来总会有人看.WebDriverW ...