_plot = $APlot; } public function Use() { if (!$this->_plot instanceof APlot){ echo '未定策略,或无效策略'.PHP_EOL; return; } $this->_plot->Use(); }}$context = new ContextPlot();$context->SetPlot(new PlotA());$context->Use(); // 触发 PlotA 策略$context->SetPlot(new PlotB());$context->Use(); // 触发 PlotB 策略$context_two = new ContextPlot();$context_two->Use(); // 未定策略,或无效策略