디자인 모델 의 행위 형 모델 ― 3.7 비망록 모델
<?php
	/**
	 * 3.7      
	 * 	  :
	 * 		           ,        
	 * 		   ,             ,  
	 * 		                  。
	 *
	 *   :
	 * 		1.    (Originator) 
	 * 			  :         Memento,  
	 * 				              ,  
	 * 				             。Originator
	 * 				         Memento     
	 * 				       。
	 * 		2.    (Memento) 
	 * 	 		  :    Originator       
	 * 	 			  ,    Originator      
	 * 	 			        Memento。      
	 * 	 			    ,Caretaker         
	 * 	 			    ,             
	 * 	 			   。Originator         
	 * 	 			  ,                
	 * 	 			    。
	 * 		3.    (Caretaker) 
	 * 			  :        Memento,     
	 * 				              。
	 *
	 * 	  :
	 * 		1.        ,           
	 * 		   
	 * 		
	 * 	  :
	 * 		1.                    
	 * 		             ,        
	 * 		         ,            
	 * 		                      
	 * 		    ,              。
	 * 		2.           。        
	 * 		                 ,    
	 * 		                     。
	 * 		3.               ,    
	 * 		        ,   ,         
	 * 		             。
	 *
	 * 	    :
	 * 		1.             ,      
	 * 		           ;
	 * 		2.                    
	 * 		    。
	 *
	 * 	
	 */
	//    
	class Originator{
		//       ,     
		private $state;
		public function setState($state){
			$this->state=$state;
		}
		public function getState(){
			return $this->state;
		}
		//     ,             
		//      Memento  
		public function CreateMemento(){
			return new Memento($this->state);
		}
		//     , Memento          
		public function setMemento(Memento $memento){
			$this->state=$memento->getState();
		}
		//    
		public function show(){
			echo '  :'.$this->state;
		}
	}
	//    
	class Memento{
		private $state;
		public function __construct($state){
			$this->state=$state;
		}
		public function getState(){
			return $this->state;
		}
	}
	//    
	//       
	class Caretaker{
		private $memento;
		public function setMemento(Memento $memento){
			$this->memento=$memento;
		}
		public function getMemento(){
			return $this->memento;
		}
	}
	//    
	//               
	$originator=new Originator();
	//       On
	$originator->setState('On');
	$originator->show();
	//               
	$caretaker=new Caretaker();
	$caretaker->setMemento($originator->CreateMemento());
	$originator->setState('Off');
	$originator->show();
	//      
	$originator->setMemento($caretaker->getMemento());
	$originator->show();
?>이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
디자인 모델 의 공장 모델, 단일 모델자바 는 23 가지 디자인 모델 (프로 그래 밍 사상/프로 그래 밍 방식) 이 있 습 니 다. 공장 모드 하나의 공장 류 를 만들어 같은 인 터 페 이 스 를 실현 한 일부 종 류 를 인 스 턴 스 로 만 드 는 것...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.