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 ...
随机推荐
- WebService学习小结
基于web的服务,服务器整理资源供多个客户端应用访问,是一种多个跨平台跨语言的应用间通信整合的方案 使用场景:天气预报.股票.地图,火车票 schema约束复习 <!-- book.xsd,定义 ...
- android studio改动module名称
新建一个android studio项目,默认Module名称是app 右键app选择Rename,或者Shift + F6也能够.重命名module名称 重命名为abc之后中,如图上面箭头所指的ap ...
- 写sql语句统计各个学生各科成绩(case when用法)
尊重原创:http://blog.csdn.net/love_java_cc/article/details/78268326 有如下一张表score: 建表语句: CREATE TABLE `sco ...
- md5加密--32位16进制小写
public class ttgameMd5 { public final static String MD5(String str) { char hexDigits[] = { // 用来将字节转 ...
- junit测试时报No runnable methods错误的解决方法
1.因为你@Test时import的是@org.testng.annotations.Test所以会报错 解决方法:改为import org.junit.Test;就可以了
- 华为nova3超级慢动作酷玩抖音,没有办法我就是这么强大!
华为nova3超级慢动作酷玩抖音,没有办法我就是这么强大! 在华为最新发布的nova 3手机上,抖音通过华为himedia SDK集成了60fps.超级慢动作等华为媒体开放能力,在加持这些能力后,抖音 ...
- linux 给用户修改权限
#添加一个用户 useradd xiaoming #设置密码 passwd xiaoming 回程 //设置密码就行了 #把用户修改成root权限 vi /etc/passwd #找到xiaoming ...
- 多媒体开发之---h264格式slice_header
从Slice_Header学习H.264 写在前面: $ H.264我是结合标准和毕厚杰的书一块学的.看句法语义时最是头疼,一大堆的元素,很需要耐心.标准中在介绍某个元素的语义时,经常会突然冒 ...
- C语言基础知识【C语言教程】
2017年7月7日23:15:51外边下雨,突然想学习c语言,所以刷一遍基础. 笔记:C 语言教程1.C 语言是一种通用的.面向过程式的计算机程序设计语言.1972 年,为了移植与开发 UNIX 操作 ...
- lua例子getglobal()
#include <stdio.h> #define MAX_COLOR 255 extern "C" { #include "lua-5.2.2/src/l ...