友元函数在物件導向程式設計中,友誼函數(friend function)是一個指定類別(class)的“朋友”,该函數被允許存取該類別中private、protected、public的資料成員。普通的函數並不能存取private和protected的資料成員,然而宣告一个函數成为一個類別的友誼函數則被允許存取private以及protected的資料成員。
生成器模式Product function getResult(); } class Director { private $builder; public function __construct($builder ) { $this->builder = $builder; } // 将部件partA partB
策略模式from application.initialize private function init() : void { var context:Context; context = new Context( new ConcreteStrategyA() ); context.execute(); context
命令模式} /* The Receiver function */ var Light = function(){ this.turnOn = function(){ console.log ('turn on')}; this.turnOff = function(){ console.log ('turn
惰性初始模式Fruit { private $type; private static $types = array(); private function __construct($type) { $this->type = $type; } public static function getFruit($type)