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 ...
随机推荐
- Singleton单例模式是最简单的设计模式,它的主要作用是保证在程序执行生命周期中,使用了单类模式的类仅仅能有一个实例对象存在。
...
- jenkins调用shell脚本 输出带颜色字体
jenkins需要安装AnsiColor插件在构建环境项选择“color ansi console output” 安装插件AnsiColor shell 脚本相关颜色设置 echo -e " ...
- WCF实现上传图片功能
初次学习实现WCF winform程序的通信,主要功能是实现图片的传输. 下面是实现步骤: 第一步: 首先建立一个类库项目TransferPicLib,导入wcf需要的引用System.Service ...
- atom无法安装插件的解决方法
atom通过setting中无法下载插件,通过apm也无法下载插件,可能是网络.config配置的问题,不好解决. 下面的方法全手动,基本属于万金油方法: 1,在atom的setting页面中点击op ...
- LVM卷组命令
一般维护命令 #vgscan //检測系统中全部磁盘 #vgck [卷组名] //用于检查卷组中卷组描写叙述区域信息的一致性. #vgdisplay [卷组名] //显示卷组的属性信息 #vg ...
- tornado 初学
tornado第一个例子 import tornado.ioloopimport tornado.web class MainHandler(tornado.web.RequestHandler): ...
- kubernetes高级之动态准入控制
系列目录 动态准入控制器文档介绍了如何使用标准的,插件式的准入控制器.但是,但是由于以下原因,插件式的准入控制器在一些场景下并不灵活: 它们需要编译到kube-apiserver里 它们仅在apise ...
- 动态注册HttpModule管道,实现global.asax功能
1.所用类库有 Microsoft.Web.Infrastructure.dll 和WebActivator.dll 2.类代码如下 using System; using System.Collec ...
- JDK自带的定时任务
import java.util.TimerTask; /** * 实现定时任务 * */ public class MyTimerTask extends TimerTask { @Override ...
- 【WPF学习笔记】之依赖属性
概述: Windows Presentation Foundation (WPF) 提供了一组服务,这些服务可用于扩展公共语言运行时 (CLR) 属性的功能.这些服务通常统称为 WPF 属性系统.由 ...