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();

时间: 2024-10-19 04:55:08

simple -- abstract的相关文章

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

Time Limit:3000MS     Memory Limit:0KB Description Background Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics (STRIPS) used a block world i

UVa101

The Blocks Problem Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 101 uDebug Description Background Many areas of Computer Science use simple, abstract domains for both analytical and empirical studi

ACM题目————The Blocks Problem

代码参考:http://www.hankcs.com/program/uva-q101-the-blocks-problem.html Description Background Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics

(STL初步)不定长数组:vector

STL是指C++的标准模板库.(存储着一些常用的算法和容器) vector是一个不定长数组.它把一些常用的操作"封装"在vector类型内部. 例如,a是一个vector.1对元素的操作有,可以用a.size()读取它的大小,a.resize()改变它的大小,a.push_back()向尾部添加元素,a.pop_back()删除最后一个元素.2对数组的操作有:a.clear()清空,a.empty()测试是否为空. vectors是一个模板类. 它的使用声明:vetor<int&

POJ 1208 The Blocks Problem

The Blocks Problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5397   Accepted: 2312 Description Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of

UVA - 101 The Blocks Problem(STL,模拟)

The Blocks Problem Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Background Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an e

POJ 1208.cpp

The Blocks Problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4815   Accepted: 2043 Description Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of

101 - The Blocks Problem

题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=37   The Blocks Problem  Background Many areas of Computer Science use simple, abstract domains for both analytical and empiric

uva 101 The Blocks Problem (模拟)

uva 101  The Blocks Problem Background Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics (STRIPS) used a block world in which a robot arm per