<?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的更多相关文章

  1. UVa 101 - The Blocks Problem(积木问题,指令操作)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  2. ACM题目————The Blocks Problem

    代码参考:http://www.hankcs.com/program/uva-q101-the-blocks-problem.html Description Background Many area ...

  3. The Blocks Problem

    Description Many areas of Computer Science use simple, abstract domains for both analytical and empi ...

  4. POJ 1208 The Blocks Problem

    The Blocks Problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5397   Accepted: 231 ...

  5. The Blocks Problem(vector)

    题目链接:http://poj.org/problem?id=1208 The Blocks Problem Time Limit: 1000MS   Memory Limit: 10000K Tot ...

  6. JDK8漫谈——代码更优雅

    简介 lambda表达式,又称闭包(Closure)或称匿名方法(anonymous method).将Lambda表达式引入JAVA中的动机源于一个叫"行为参数"的模式.这种模式 ...

  7. Winter-2-STL-D The Blocks Problem 解题报告及测试数据

    Time Limit:3000MS     Memory Limit:0KB Description Background Many areas of Computer Science use sim ...

  8. 4.3 Writing a Grammar

    4.3 Writing a Grammar Grammars are capable of describing most, but not all, of the syntax of program ...

  9. EOJ 1501/UVa The Blocks Problem

    Many areas of Computer Science use simple, abstract domains for both analytical and empirical studie ...

随机推荐

  1. lodash 数组裁剪 drop

    _.drop(array, [n=1]) 裁剪数组中的前 N 个数组,返回剩余的部分. <!DOCTYPE html> <html lang="zh"> & ...

  2. How to Use HTML5 FUll Screen API(怎样使用HTML5全屏接口)

    原文链接:http://www.sitepoint.com/use-html5-full-screen-api/ 假设你不太喜欢变化太快的东西,那么web开发可能不适合你. 我曾在2012年末有写过F ...

  3. const_cast去除const限制,同一片内存

    本质很简单,但一些优化 和 编程上的错误,却让人看不清本质. :const_cast<type_id> (expression) 该运算符用来修改类型的const或volatile属性.除 ...

  4. JFinal中Controller的应用

    部分方法: 1.获取参数:getPara(String name); getParaToInt(String name) ,将返回参数的值转为int: getPara() ,url中参数连接为/v1- ...

  5. ConcurrentHashMap的使用和原理

    呵呵呵,原理nmb. HashTable,HashMap,ConcurrentHashMap 当你作为一个菜鸡的时候,别人就会那这个来问你. 为什么要用ConcurrentHashMap,因为Hash ...

  6. Hotel poj 3667

    Language: Default Hotel     Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 18020   Acc ...

  7. homebrew可以管理众多开源软件的安装和卸载

    通过homebrew可以管理众多开源软件的安装和卸载. 参考https://github.com/mxcl/homebrew/wiki 1. 安装: ruby -e "$(curl -fsS ...

  8. 嵌入式开发之davinci--- 8148/8168/8127 中的大屏分布式拼接显示系统

    其实在接触从12年接触8127系列ipnc 时看到200w和500w的高清像素,我就萌生了视频拼接的兴趣,没想到今年的安博会就有公司推出产品了,它就是上海的环视科技,从他的主页可以看到,明显的有个只能 ...

  9. InitialContext和lookup

    http://wxg6203.iteye.com/blog/680830 最近因为工作需要开始学习Ejb3,遇到了一个让我很郁闷的事情,做一下小小的总结——小心new InitialContext() ...

  10. C语言基础知识【函数】

    C 函数1.函数是一组一起执行一个任务的语句.每个 C 程序都至少有一个函数,即主函数 main() ,所有简单的程序都可以定义其他额外的函数.您可以把代码划分到不同的函数中.如何划分代码到不同的函数 ...