成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

【編程課堂】Php設(shè)計(jì)模式(三):行為型模式

starsfun / 3517人閱讀

摘要:代碼實(shí)現(xiàn)迭代器模式注意被迭代對象屬性是私有的觀察者模式又叫發(fā)布訂閱模式,當(dāng)一個(gè)主體對象發(fā)生改變時(shí),依賴它的多個(gè)觀察者對象都得到通知并自動更新響應(yīng)。

在上一篇我們講了結(jié)構(gòu)型模式,結(jié)構(gòu)型模式是討論類和對象的結(jié)構(gòu)的??偣灿?種。而今天我們來介紹一下行為型模式。

一、什么是行為型模式?

1、設(shè)計(jì)模式:

是一套被反復(fù)使用、多數(shù)人知曉的、經(jīng)過分類編目的、代碼設(shè)計(jì)的總結(jié)。就好像杯子,是被前人設(shè)計(jì)出來的,實(shí)現(xiàn)了儲存水的功能,解決了人們的喝水問題。大多數(shù)人喝水都用杯子。但是你不必自己再重做另外方法再做一種容器,而實(shí)現(xiàn)的也是同樣的功能,只要會用別人做出來的杯子喝水就能達(dá)到目的。但是杯子有很多中,實(shí)現(xiàn)喝水的方式也不同,比如茶水杯子,咖啡杯,啤酒杯子等等,要選擇適合自己的杯子,就如茶水要用帶過濾網(wǎng)的杯子,如果用不帶過濾網(wǎng)的會喝一嘴茶葉。合適的才是最好的。

總結(jié)出來設(shè)計(jì)模式的特性如下:

1.普遍性:經(jīng)過前輩們的使用,大多人都實(shí)用的,總結(jié)提煉不斷的提升被普遍認(rèn)為是實(shí)現(xiàn)某種事物的最有效的方法。

2.封裝性:既然是方法那我們就不用太關(guān)心細(xì)節(jié)是怎么實(shí)現(xiàn)的,而主要是學(xué)習(xí)怎么用這些方法模式,從而達(dá)到自己的目的。

3.面向?qū)ο笮裕褐笓]對象做事。把復(fù)雜問題簡單化。

4.最優(yōu)性:要充分相信適合的就是最好的。

2、面向?qū)ο螅?/p>

或許你對面向?qū)ο筮€有疑問?指揮對象做事,把復(fù)雜問題簡單化。那么我們就來舉個(gè)例子說明。比如我們?nèi)ワ埖瓿燥?,會叫服?wù)員然后點(diǎn)菜,那我們就是指揮服務(wù)員做事,至于服務(wù)員怎么讓廚師做,廚師怎么做,這些我們都不管。我們只管是否能吃到我們叫到的菜。這個(gè)就是把復(fù)雜事情簡單化了。我們不用自己做菜,也不用知道菜怎么做,我們指揮服務(wù)員就行了,吃飯這件事就由復(fù)雜的做菜之類的變成吃這個(gè)簡單的事了。

3、行為型模式:

就是描述類和對象之間的通信和職責(zé)的。簡而言之,就是類和對象扮演什么角色,還有怎么扮演這個(gè)角色的問題。

二、行為型模式的種類

大體上分為三個(gè)大類:常見模式、已知模式、深度模式

常見模式包括: 模版方法模式命令模式 迭代器模式 觀察者模式 中介者模式 狀態(tài)式 職責(zé)鏈模式 策略模式

已知模式包括:備忘錄模式

深度模式包括:解釋器模式 訪問者模式

下面來介紹常見模式

? 常見模式

1、模版方法模式(Template):

定義一個(gè)操作中的算法骨架,而將一些實(shí)現(xiàn)步驟延遲到子類當(dāng)中實(shí)現(xiàn)。就像一個(gè)豆?jié){機(jī),不管放進(jìn)去的是紅豆還是黑豆,出來的都是豆?jié){。

好處:擴(kuò)展性好,封裝不變的代碼,擴(kuò)展可變的代碼

弊端:靈活性差,不能改變骨架部分。

應(yīng)用場景:一類或一組具有共性的事物中

代碼實(shí)現(xiàn)

/**
*

模板方法模式 Template
*/

function output($string) {
echo $string . "n";
}
class Request {
public$token = "";
publicfunction __construct() {
$this->token ="0c6b7289f5334ed2b697dd461eaf9812";
}
}
class Response {
publicfunction render($content) {
output(sprintf("response-render: %s",$content));
}
publicfunction redirect($uri) {
output(sprintf("response-redirect: %s", $uri));
}
publicfunction json($data) {
output(sprintf("response-data: %s", json_encode($data)));
}
}
//父類,抽象類
abstract class Controller{
//封裝了輸入輸出
protected$request;
protected$response;
//返回?cái)?shù)據(jù)
protected$data = "data";
publicfunction __construct($request, $response){
$this->request = $request;
$this->response = $response;
}
//執(zhí)行請求函數(shù),定義總體算法(template method),final防止被復(fù)寫(不允許子類改變總體算法)
publicfinal function execute(){
$this->before();
if($this->valid()){
$this->handleRequest();
}
$this->after();
}
//定義hook methodbefore,做一些具體請求的前置處理
//非abstract方法,子類可以選擇覆蓋或不覆蓋,默認(rèn)什么都不做
protectedfunction before(){
}
//定義hook methodvalid,做請求的數(shù)據(jù)驗(yàn)證
//非abstract方法,子類可以選擇覆蓋或不覆蓋,默認(rèn)返回驗(yàn)證通過
protectedfunction valid(){
returntrue;
}
//定義hook methodhandleRequest,處理請求
//定義為abstract方法,子類必須實(shí)現(xiàn)或也聲明為抽象方法(由子類的子類負(fù)責(zé)實(shí)現(xiàn))
abstractfunction handleRequest();
//定義hook methodafter,做一些請求的后置處理
//非abstract方法,子類可以選擇覆蓋或不覆蓋,默認(rèn)直接輸出數(shù)據(jù)
protectedfunction after(){
$this->response->render($this->data);
}
}
//子類1,實(shí)現(xiàn)父類開放的具體算法
class User extends Controller{
//覆蓋before方法,實(shí)現(xiàn)具體算法,這是一個(gè)處理用戶數(shù)據(jù)操作的控制器
//因此,我們選擇在before里面判斷用戶是否已經(jīng)登錄了,這里簡單判斷下session數(shù)據(jù)
functionbefore(){
if(empty($_SESSION["auth"])){
//沒登錄就直接跳轉(zhuǎn)了,不再執(zhí)行后續(xù)的操作
$this->response->redirect("user/login.php");
}
}
//覆蓋valid方法,這里我們驗(yàn)證用戶提交數(shù)據(jù)中有沒有帶驗(yàn)證token
functionvalid(){
if(isset($this->request->token)){
return true;
}
returnfalse;
}
//覆蓋handleRequest方法,必選,以為父類中聲明了abstract了
functionhandleRequest(){
//做具體處理,一般根據(jù)參數(shù)執(zhí)行不同的業(yè)務(wù)邏輯
}
//這個(gè)類我們選擇不覆蓋after方法,使用默認(rèn)處理方式
}
//子類2,實(shí)現(xiàn)父類開放的具體算法
class Post extends Controller{
//這個(gè)類我們選擇不覆蓋before方法,使用默認(rèn)處理方式
//這個(gè)類我們選擇不覆蓋valid方法,使用默認(rèn)處理方式
//覆蓋handleRequest方法,必選,以為父類中聲明了abstract了
functionhandleRequest(){
//做具體處理,一般根據(jù)參數(shù)執(zhí)行不同的業(yè)務(wù)邏輯
$this->data = array("title" => "ucai");
}
//覆蓋after方法,使用json格式輸出數(shù)據(jù)
functionafter(){
$this->response->json($this->data);
}
}
class Client {
publicstatic function test(){
$request = new Request();
$response = new Response();
//最終調(diào)用
$user= new User($request, $response);
$user->execute();
//最終調(diào)用
$post= new Post($request, $response);
$post->execute();
}
}
Client::test();

2、命令模式(Command) :

行為請求者與行為實(shí)現(xiàn)者解耦。就像軍隊(duì)里的“敬禮”,不管是誰聽到這個(gè)命令都會做出標(biāo)準(zhǔn)的敬禮動作。

好處:便于添加和修改行為,便于聚合多個(gè)命令

弊端:造成過多具體的命令類

應(yīng)用場景:對要操作的對象,進(jìn)行的相同操作

代碼實(shí)現(xiàn)
/**
*

命令模式 Command
*/

function output($string) {
echo $string . "n";
}
class Document {
private$name = "";
public function __construct($name) {
$this->name = $name;
}
publicfunction showText() {
output(sprintf("showText: %s", $this->name));
}
publicfunction undo() {
output(sprintf("undo-showText: %s", $this->name));
}
}
class Graphics {
private$name = "";
publicfunction __construct($name) {
$this->name = $name;
}
publicfunction drawCircle() {
output(sprintf("drawCircle: %s", $this->name));
}
publicfunction undo() {
output(sprintf("undo-drawCircle: %s", $this->name));
}
}
class Client {
publicstatic function test() {
$document = newDocument("A");
$graphics = newGraphics("B");
$document->showText();
$graphics->drawCircle();
$document->undo();
}
}
Client::test();
/**
*

命令模式 Command
*/

function output($string) {
echo $string . "n";
}
interface Command {
publicfunction execute();
publicfunction undo();
}
class Document implements Command {
private$name = "";
publicfunction __construct($name) {
$this->name = $name;
}
publicfunction execute() {
output(sprintf("showText: %s", $this->name));
}
publicfunction undo() {
output(sprintf("undo-showText: %s", $this->name));
}
}
class Graphics implements Command {
private$name = "";
publicfunction __construct($name) {
$this->name = $name;
}
publicfunction execute() {
output(sprintf("drawCircle: %s", $this->name));
}
publicfunction undo() {
output(sprintf("undo-drawCircle: %s", $this->name));
}
}
class Client {
publicstatic function test() {
$array = array();
array_push($array, new Document("A"));
array_push($array, new Document("B"));
array_push($array, new Graphics("C"));
array_push($array, new Graphics("D"));
foreach ($array as $command) {
$command->execute();
}
$top = array_pop($array);
$top->undo();
}
}
Client::test();
/**
*

命令模式 Command
*

*/
function output($string) {
echo $string . "n";
}
interface Command {
publicfunction execute();
publicfunction undo();
}
class Document {
private$name = "";
publicfunction __construct($name) {
$this->name = $name;
}
publicfunction showText() {
output(sprintf("showText: %s", $this->name));
}
publicfunction undo() {
output(sprintf("undo-showText: %s", $this->name));
}
}
class Graphics {
private$name = "";
publicfunction __construct($name) {
$this->name = $name;
}
publicfunction drawCircle() {
output(sprintf("drawCircle: %s", $this->name));
}
publicfunction undo() {
output(sprintf("undo-drawCircle: %s", $this->name));
}
}
class DocumentCommand implements Command {
private$obj = "";
publicfunction __construct(Document $document) {
$this->obj = $document;
}
publicfunction execute() {
$this->obj->showText();
}
publicfunction undo() {
$this->obj->undo();
}
}
class GraphicsCommand implements Command {
private$obj = "";
publicfunction __construct(Graphics $graphics) {
$this->obj = $graphics;
}
publicfunction execute() {
$this->obj->drawCircle();
}
publicfunction undo() {
$this->obj->undo();
}
}
class Client {
publicstatic function test() {
$array = array();
array_push($array, new DocumentCommand(new Document("A")));
array_push($array, new DocumentCommand(new Document("B")));
array_push($array, new GraphicsCommand(newGraphics("C")));
array_push($array, new GraphicsCommand(new Graphics("D")));
foreach ($array as $command) {
$command->execute();
}
$top = array_pop($array);
$top->undo();
}
}
Client::test();

3、迭代器模式(Iterator):

訪問聚合對象內(nèi)容而不暴露內(nèi)部結(jié)構(gòu)。就像一個(gè)雙色球彩票開獎(jiǎng)一樣,每次都是搖出七個(gè)球,不能能搖不是七個(gè)球的中獎(jiǎng)號碼組合。

好處:以不同方式遍歷一個(gè)集合

弊端:每次遍歷都是整個(gè)集合,不能多帶帶取出元素

應(yīng)用場景:需要操作集合里的全部元素。

代碼實(shí)現(xiàn):

/**
*

迭代器模式 Iterator
*/

function output($string) {
echo $string . "n";
}
class RecordIterator implements Iterator{
private$position = 0;
//注意:被迭代對象屬性是私有的
private$records = array();
publicfunction __construct(Array $records) {
$this->position = 0;
$this->records = $records;
}
functionrewind() {
$this->position = 0;
}
functioncurrent() {
return$this->records[$this->position];
}
functionkey() {
return$this->position;
}
functionnext() {
++$this->position;
}
functionvalid() {
returnisset($this->records[$this->position]);
}
}
class PostListPager {
protected$record = array();
protected$total = 0;
protected$page = 0;
protected$size = 0;
publicfunction __construct($category, $page, $size) {
$this->page = $page;
$this->size = $size;
//query db
$total = 28;
$this->total = $total;
$record = array(
0 => array("id"=> "1"),
1 => array("id"=> "2"),
2 => array("id"=> "3"),
3 => array("id"=> "4"),
);
//
$this->record = $record;
}
publicfunction getIterator() {
return newRecordIterator($this->record);
}
publicfunction getMaxPage() {
$max = intval($this->total /$this->size);
return $max;
}
publicfunction getPrevPage() {
return max($this->page - 1,1);
}
publicfunction getNextPage() {
return min($this->page + 1,$this->getMaxPage());
}
}
class Client {
publicstatic function test(){
$pager = new PostListPager(1,2, 4);
foreach ($pager->getIterator() as $key => $val) {
output(sprintf("Key[%d],Val[%s]", $key, json_encode($val)));
}
output(sprintf("MaxPage[%d]", $pager->getMaxPage()));
output(sprintf("Prev[%d]", $pager->getPrevPage()));
output(sprintf("Next[%d]", $pager->getNextPage()));
$iterator =$pager->getIterator();
while($iterator->valid()){
print_r($iterator->current());
$iterator->next();
}
$iterator->rewind();
}
}
Client::test();

4、觀察者模式(Observer):

又叫發(fā)布訂閱模式,當(dāng)一個(gè)主體對象發(fā)生改變時(shí),依賴它的多個(gè)觀察者對象都得到通知并自動更新響應(yīng)。就像報(bào)社一樣,今天發(fā)布的消息只要是看這份報(bào)紙的人看到的都是同樣的內(nèi)容。如果發(fā)布另一份報(bào)紙,也是一樣的。

好處:廣播式通信,范圍大,一呼百應(yīng),便于操作一個(gè)組團(tuán),“公有制”

弊端:不能多帶帶操作組團(tuán)里的個(gè)體,不能實(shí)行按需分配

應(yīng)用場景:操作多個(gè)對象,并操作相同。

代碼實(shí)現(xiàn):
/**

優(yōu)才網(wǎng)公開課示例代碼
*

觀察者模式 Observer
*/

function output($string) {
echo $string . "n";
}
//訂單數(shù)據(jù)對象簡單模擬,這個(gè)是實(shí)際需要被觀察的對象(Subject),但是我們將其獨(dú)立,然后
//通過構(gòu)造方法傳入到我們模式中的Subject中,這樣使具體業(yè)務(wù)更加獨(dú)立
class Order{
//訂單號
private$id = "";
//用戶ID
private$userId = "";
//用戶名
private$userName = "";
//價(jià)格
private$price = "";
//下單時(shí)間
private$orderTime = "";
//訂單數(shù)據(jù)填充簡單模擬,實(shí)際應(yīng)用中可能會讀取用戶表單輸入并處理
publicfunction __set($name, $value){
if(isset($this->$name)){
$this->$name = $value;
}
}
//獲取訂單屬性
public function__get($name){
if(isset($this->$name)){
return $this->$name;
}
return"";
}
}
//假設(shè)的DB類,便于測試,實(shí)際會存入真實(shí)數(shù)據(jù)庫
class FakeDB{
publicfunction save($data){
returntrue;
}
}
class Client {
publicstatic function test() {
//初始化一個(gè)訂單數(shù)據(jù)
$order= new Order();
$order->id = 1001;
$order->userId = 9527;
$order->userName = "God";
$order->price = 20.0;
$order->orderTime = time();
//向數(shù)據(jù)庫保存訂單
$db =new FakeDB();
$result = $db->save($order);
if($result){
//實(shí)際應(yīng)用可能會寫到日志文件中,這里直接輸出
output( "[OrderId:{$order->id}]
UseId:{$order->userId}" );
//實(shí)際應(yīng)用會調(diào)用郵件發(fā)送服務(wù)如sendmail,這里直接輸出
output( "Dear {$order->userName}: Your order {$order->id}
wasconfirmed!" );
//實(shí)際應(yīng)用會調(diào)用郵件發(fā)送服務(wù)如sendmail,這里直接輸出
output( "Dear Manager: User{$order->userName}(ID:{$order->userId})
submitted a new order {$order->id},please handle it ASAP!" );
}
}
}
Client::test();
/**
*

觀察者模式 Observer
*/

function output($string) {
echo $string . "n";
}
//訂單數(shù)據(jù)對象簡單模擬,這個(gè)是實(shí)際需要被觀察的對象(Subject),但是我們將其獨(dú)立,然后
//通過構(gòu)造方法傳入到我們模式中的Subject中,這樣使具體業(yè)務(wù)更加獨(dú)立
class Order{
//訂單號
private$id = "";
//用戶ID
private$userId = "";
//用戶名
private$userName = "";
//價(jià)格
private$price = "";
//下單時(shí)間
private$orderTime = "";
//訂單數(shù)據(jù)填充簡單模擬,實(shí)際應(yīng)用中可能會讀取用戶表單輸入并處理
publicfunction __set($name, $value){
if(isset($this->$name)){
$this->$name = $value;
}
}
//獲取訂單屬性
publicfunction __get($name){
if(isset($this->$name)){
return $this->$name;
}
return"";
}
}
//被觀察者, 負(fù)責(zé)維護(hù)觀察者并在變化發(fā)生是通知觀察者
class OrderSubject implements SplSubject {
private$observers;
private$order;
publicfunction __construct(Order $order) {
$this->observers = new SplObjectStorage();
$this->order = $order;
}
//增加一個(gè)觀察者
publicfunction attach(SplObserver $observer) {
$this->observers->attach($observer);
}
//移除一個(gè)觀察者
publicfunction detach(SplObserver $observer) {
$this->observers->detach($observer);
}
//通知所有觀察者
publicfunction notify() {
foreach ($this->observers as $observer) {
$observer->update($this);
}
}
//返回主體對象的具體實(shí)現(xiàn),供觀察者調(diào)用
publicfunction getOrder() {
return$this->order;
}
}
//記錄業(yè)務(wù)數(shù)據(jù)日志 (ActionLogObserver),實(shí)際可能還要抽象一層以處理不同的Action(業(yè)務(wù)操作),這里省略
class ActionLogObserver implements SplObserver{
publicfunction update(SplSubject $subject) {
$order = $subject->getOrder();
//實(shí)際應(yīng)用可能會寫到日志文件中,這里直接輸出
output( "[OrderId:{$order->id}]
UseId:{$order->userId}" );
}
}
//給用戶發(fā)送訂單確認(rèn)郵件 (UserMailObserver)
class UserMailObserver implements SplObserver{
publicfunction update(SplSubject $subject) {
$order = $subject->getOrder();
//實(shí)際應(yīng)用會調(diào)用郵件發(fā)送服務(wù)如sendmail,這里直接輸出
output( "Dear {$order->userName}: Your order {$order->id}
wasconfirmed!" );
}
}
//給管理人員發(fā)訂單處理通知郵件 (AdminMailObserver)
class AdminMailObserver implements SplObserver{
publicfunction update(SplSubject $subject) {
$order = $subject->getOrder();
//實(shí)際應(yīng)用會調(diào)用郵件發(fā)送服務(wù)如sendmail,這里直接輸出
output( "Dear Manager: User{$order->userName}(ID:{$order->userId})
submitted a new order{$order->id}, please handle it ASAP!" );
}
}
//假設(shè)的DB類,便于測試,實(shí)際會存入真實(shí)數(shù)據(jù)庫
class FakeDB{
publicfunction save($data){
returntrue;
}
}
class Client {
publicstatic function test() {
//初始化一個(gè)訂單數(shù)據(jù)
$order= new Order();
$order->id = 1001;
$order->userId = 9527;
$order->userName = "God";
$order->price = 20.0;
$order->orderTime = time();
//綁定觀察者
$subject = new OrderSubject($order);
$actionLogObserver = new ActionLogObserver();
$userMailObserver = newUserMailObserver();
$adminMailObserver = new AdminMailObserver();
$subject->attach($actionLogObserver);
$subject->attach($userMailObserver);
$subject->attach($adminMailObserver);
//向數(shù)據(jù)庫保存訂單
$db =new FakeDB();
$result = $db->save($order);
if($result){
//通知觀察者
$subject->notify();
}
}
}
Client::test();

5、中介者模式(Mediator):

用中介對象封裝一系列的對象交互,中介使各對象不需要顯式地相互引用。類似于郵局,郵寄者和收件者不用自己跑很遠(yuǎn)路,通過郵局就可以。

好處:簡化了對象之間的關(guān)系,減少子類的生成

弊端:中介對象可能變得非常復(fù)雜,系統(tǒng)難以維護(hù)

應(yīng)用場景:不需要顯示地建立交互

代碼實(shí)現(xiàn):

/**
*
*/
function output($string) {
echo $string . "n";
}
abstract class Mediator { // 中介者角色
abstractpublic function send($message,$colleague);
}
abstract class Colleague { // 抽象對象
private$_mediator = null;
publicfunction __construct($mediator) {
$this->_mediator = $mediator;
}
publicfunction send($message) {
$this->_mediator->send($message,$this);
}
abstractpublic function notify($message);
}
class ConcreteMediator extends Mediator { // 具體中介者角色
private$_colleague1 = null;
private$_colleague2 = null;
publicfunction send($message,$colleague) {
if($colleague == $this->_colleague1) {
$this->_colleague1->notify($message);
} else{
$this->_colleague2->notify($message);
}
}
publicfunction set($colleague1,$colleague2) {
$this->_colleague1 = $colleague1;
$this->_colleague2 = $colleague2;
}
}
class Colleague1 extends Colleague { // 具體對象角色
publicfunction notify($message) {
output(sprintf("Colleague-1: %s", $message));
}
}
class Colleague2 extends Colleague { // 具體對象角色
publicfunction notify($message) {
output(sprintf("Colleague-2: %s", $message));
}
}
class Client {
publicstatic function test(){
//client
$objMediator = new ConcreteMediator();
$objC1= new Colleague1($objMediator);
$objC2= new Colleague2($objMediator);
$objMediator->set($objC1,$objC2);
$objC1->send("to c2 from c1");
$objC2->send("to c1 from c2");
}
}
Client::test();

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/22751.html

相關(guān)文章

  • 編程課堂php設(shè)計(jì)模式(二):結(jié)構(gòu)模式(續(xù))

    摘要:能夠協(xié)調(diào)調(diào)用者和被調(diào)用者,能夠在一定程度上降低系統(tǒng)的耦合性。特點(diǎn)低耦合性,獨(dú)立性好,安全性應(yīng)用客戶訪問不到或者被訪問者希望隱藏自己,所以通過代理來訪問自己。 我們接著上面的幾種模式繼續(xù)講: 4、組合模式 將對象組合成樹形結(jié)構(gòu)表示部分-整體的層次結(jié)構(gòu)。 特點(diǎn):靈活性強(qiáng) 應(yīng)用:對象的部分-整體的層次結(jié)構(gòu),模糊組合對象和簡單對象處理問題 代碼實(shí)現(xiàn) /** 組合模式* *///繼承模式clas...

    Nekron 評論0 收藏0
  • PHP基礎(chǔ)

    摘要:分別為適配器模式,裝飾器模式,代理模式,外觀模式,橋接模式,組合模式,享元模式。設(shè)計(jì)模式五適配器模式適配器模式將某個(gè)對象的接生成器和協(xié)程的實(shí)現(xiàn)在這篇文章中,作者針對那些比較難以理解的概念,以一個(gè)更為通俗的方式去講明白。。 PHP 源碼注解 PHP 的詳細(xì)源碼注解 PHP 字符串操作整理 一些有關(guān)字符串的常用操作。 Redis 常見七種使用場景 (PHP 實(shí)戰(zhàn)) 這篇文章主要介紹利用 R...

    HtmlCssJs 評論0 收藏0
  • 技術(shù)攻略】php設(shè)計(jì)模式(一):簡介及創(chuàng)建模式

    摘要:我們分三篇文章來總結(jié)一下設(shè)計(jì)模式在中的應(yīng)用,這是第一篇?jiǎng)?chuàng)建型模式。二提煉設(shè)計(jì)模式的幾個(gè)原則開閉原則模塊應(yīng)對擴(kuò)展開放,而對修改關(guān)閉。工廠模式實(shí)現(xiàn)定義一個(gè)用于創(chuàng)建對象的接口,讓子類決定實(shí)例化哪一個(gè)類。設(shè)計(jì)模式的第一部分,創(chuàng)建型模式就總結(jié)完了。 我們分三篇文章來總結(jié)一下設(shè)計(jì)模式在PHP中的應(yīng)用,這是第一篇?jiǎng)?chuàng)建型模式。一、設(shè)計(jì)模式簡介 首先我們來認(rèn)識一下什么是設(shè)計(jì)模式: 設(shè)計(jì)模式是一套被反復(fù)使...

    dongxiawu 評論0 收藏0
  • 優(yōu)才公開課筆記:php設(shè)計(jì)模式(一) 之單例模式

    摘要:最近開展了三次設(shè)計(jì)模式的公開課,現(xiàn)在來總結(jié)一下設(shè)計(jì)模式在中的應(yīng)用,這是第一篇?jiǎng)?chuàng)建型模式之單例模式。不過因?yàn)椴恢С侄嗑€程所以不需要考慮這個(gè)問題了。 最近開展了三次設(shè)計(jì)模式的公開課,現(xiàn)在來總結(jié)一下設(shè)計(jì)模式在PHP中的應(yīng)用,這是第一篇?jiǎng)?chuàng)建型模式之單例模式。 一、設(shè)計(jì)模式簡介 首先我們來認(rèn)識一下什么是設(shè)計(jì)模式: 設(shè)計(jì)模式是一套被反復(fù)使用、容易被他人理解的、可靠的代碼設(shè)計(jì)經(jīng)驗(yàn)的總結(jié)。 設(shè)計(jì)模式不...

    guyan0319 評論0 收藏0
  • PHP 設(shè)計(jì)模式概述

    摘要:創(chuàng)建型模式主要有以下五種簡單工廠模式和工廠方法模式抽象工廠模式單例模式建造者模式原型模式在設(shè)計(jì)模式一書中將工廠模式分為兩類工廠方法模式與抽象工廠模式。 一、 設(shè)計(jì)模式(Design pattern)是什么 設(shè)計(jì)模式是一套被反復(fù)使用、多數(shù)人知曉、經(jīng)過分類編目的代碼設(shè)計(jì)的經(jīng)驗(yàn)總結(jié)。使用設(shè)計(jì)模式是為了可重用代碼、讓代碼更容易被他人理解、保證代碼可靠性。 二、 為什么會有設(shè)計(jì)模式 在軟件開發(fā)過...

    IntMain 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<