ビルダーモード(Builderパターン)
定義:シンプルな複数のオブジェクトを使用して、複雑なオブジェクトを構築するためにステップバイステップ。 目的:それは同じ構築物は異なる表現を作成することができるような相分離処理を表す複雑なビルド。 シーン:いくつかの基本的な構成は変更されません、と時間の組み合わせが頻繁に変更されます。
//製品クラスの宣言 クラスの製品{ コンストラクタ(){ } } //ビルダークラス宣言 クラスBuilderProduct { コンストラクタ(){ //製品名構築 this.nameBuilder =(名)=> { | this.name =名前を| NULL } //ビルド製品バージョン this.versionBuilder =(バージョン)=> { this.versionバージョン|| = NULL } //ビルド製造日 this.createTimeBuilder =(CREATETIME)=> { this.createTime = CREATETIME || NULL } //製品組成ビルド this.getProduct =()=> { せ新新製品の製品=() IF(this.name){ builderProduct.createTimeBuilder(demands.createTime) product.name = this.name } IF(this.version){ product.version = this.version } IF(this.createTime){ product.createTime = this.createTime } 戻り製品 } } } //声明一个需求类 クラス需要{ コンストラクタ(需要が){ せbuilderProduct =新しいBuilderProduct() builderProduct.nameBuilder(demands.name) builderProduct.versionBuilder(demands.version) を返すbuilderProduct.getProduct() } } 聞かせて需要=新たな需要({ 名: 'SKILL.NULL' })