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 ...
随机推荐
- 51单片机 | 实现SMC1602液晶屏显示实例
———————————————————————————————————————————— LCD1602 - - - - - - - - - - - - - - - - - - - - - - - - ...
- linux常用命令(个人学习笔记)
个人说明:学习linux也有半年左右的时间了,从一开始的只会简单的开关机,到现在的熟悉应用一些简单的命令,还是有些进步的,不过对于我这种菜鸟来说,如果不经常用,发现忘的很快.所以就把在学习过程中遇到的 ...
- CSS遮罩层,全兼容
<script type="text/javascript"> $(function(){ $('#divLocker').css({ "position&q ...
- angularjs中的$q
先说说什么是Promise,什么是$q吧.Promise是一种异步处理模式,有很多的实现方式,比如著名的Kris Kwal's Q还有JQuery的Deffered. 什么是Promise 以前了解过 ...
- unity3d WebPlayer版本号音效无声音问题
unity web player,其是一款浏览器执行unity3d游戏引擎公布的游戏的插件,和Flash Player非常像,安全无毒应该是你玩某款网页游戏安装的.假设以后不玩了就能够卸载 Unity ...
- MySQL四-2:完整性约束
阅读目录 一 介绍 二 not null与default 三 unique 四 primary key 五 auto_increment 六 foreign key 七 作业 一 介绍 约束条件与数据 ...
- Stockbroker Grapevine - poj 1125 (Floyd算法)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 30454 Accepted: 16659 Description S ...
- Cannot merge new index 65781 into a non-jumbo instruction! 问题解决(网上摘抄)
我的报了这个错 Error:Execution failed for task ':app:transformClassesWithDexForDebug'.> com.android.buil ...
- 多媒体开发之--- h264 图像、帧、片、NALU
图像.帧.片.NALU 是学习 H.264的人常常感到困惑的一些概念,我在这里对自己的理解做一些阐述,欢迎大家讨论: H.264 是一次概念的革新,它打破常规,完全没有 I 帧.P帧.B 帧的概念,也 ...
- python pymysql安装
==================pymysql=================== 由于 MySQLdb 模块还不支持 Python3.x,所以 Python3.x 如果想连接MySQL需要安装 ...