iOS設計模式-生成器

定義:將一個產品的內部表象與產品的生成過程分割開來,從而可以使一個建造過程生成具有不同的內部表象的產品對象。

類型:對象創建

類圖:

#import <Foundation/Foundation.h>
@interface Character : NSObject @property(nonatomic, assign)float protection; @property(nonatomic, assign)float power; @property(nonatomic, assign)float strength; @property(nonatomic, assign)float stamina; @property(nonatomic, assign)float intelligence; @property(nonatomic, assign)float agility; @property(nonatomic, assign)float aggressiveness; @end
#import "Character.h"@implementation Character- (instancetype)init{if (self = [super init]) {_protection = 1.0;_power = 1.0;_strength = 1.0;_stamina = 1.0;_intelligence = 1.0;_agility = 1.0;_aggressiveness = 1.0;}return self;
}@end
#import <Foundation/Foundation.h>
#import "Character.h"@interface CharacterBuilder : NSObject{Character * _character;
}
@property(nonatomic, readonly)Character *character;- (CharacterBuilder *)buildNewCharacter;
- (CharacterBuilder *)builStrength:(float)value;
@end
#import "CharacterBuilder.h"@implementation CharacterBuilder- (CharacterBuilder *)buildNewCharacter{_character = [[Character alloc]init];return self;
}
- (CharacterBuilder *)builStrength:(float)value{_character.strength = value;return self;
}@end
#import "CharacterBuilder.h"@interface StandardCharacterBuilder : CharacterBuilder@end
#import "StandardCharacterBuilder.h"@implementation StandardCharacterBuilder- (CharacterBuilder *)builStrength:(float)value{_character.protection = value;_character.power = value;return [super builStrength:value];
}@end
#import <Foundation/Foundation.h>
#import "StandardCharacterBuilder.h"@interface ChasingGame : NSObject- (Character *)createPlayer:(CharacterBuilder *)builder;
- (Character *)createEnemy:(CharacterBuilder *)builder;@end
#import "ChasingGame.h"@implementation ChasingGame- (Character *)createPlayer:(CharacterBuilder *)builder{[builder buildNewCharacter];[builder builStrength:50.0];return [builder character];
}- (Character *)createEnemy:(CharacterBuilder *)builder{[builder buildNewCharacter];[builder builStrength:80.0];return [builder character];
}@end

?

轉載于:https://www.cnblogs.com/muzijun/p/5749750.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/395410.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/395410.shtml
英文地址,請注明出處:http://en.pswp.cn/news/395410.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

《Android 應用案例開發大全(第二版)》——導讀

本節書摘來自異步社區《Android 應用案例開發大全&#xff08;第二版&#xff09;》一書中的目錄 &#xff0c;作者 吳亞峰 , 于復興 , 杜化美&#xff0c;更多章節內容可以訪問云棲社區“異步社區”公眾號查看 目 錄 第1章 初識廬山真面目——Android簡介 1.1 Android的誕生 1…

模塊--sys模塊

sys模塊是與python解釋器交互的一個接口 import sys sys.path #python解釋器找模塊的環境變量import sys print(sys.path)結果:[H:\\王文靜\\python\\4練習\\課堂練習, H:\\王文靜\\python, C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36\\pyth…

匿名方法

與前面的可空類型是一樣的&#xff0c;匿名方法也是C# 2.0里面提出來的。 1 匿名方法 1.1 什么是匿名方法&#xff1f; 顧名思義&#xff0c;就是沒有名稱的方法&#xff0c;因為沒有名稱&#xff0c;匿名方法只能在函數定義&#xff08;匿名方法是把方法的實現和定義嵌套在了一…

使用React,Redux和Router進行真正的集成測試

by Marcelo Lotif通過馬塞洛洛蒂夫(Marcelo Lotif) 使用React&#xff0c;Redux和Router進行真正的集成測試 (Real integration tests with React, Redux and Router) After being bitten a couple of times by bad refactoring and a broken app?—?even with all my tests…

Go語言從入門到精通 - 數據類型轉換

本節核心內容 介紹 Go語言數據類型轉換的格式介紹 數據轉換代碼示例介紹 數據轉換過程中的注意事項 本小節視頻教程和代碼&#xff1a;百度網盤 可先下載視頻和源碼到本地&#xff0c;邊看視頻邊結合源碼理解后續內容&#xff0c;邊學邊練。 Go語言數據類型轉換 Go 語言使用類型…

JNI通過線程c回調java層的函數

1、參看博客&#xff1a;http://www.jianshu.com/p/e576c7e1c403 Android JNI 篇 - JNI回調的三種方法&#xff08;精華篇&#xff09; 2、參看博客&#xff1a; JNI層線程回調Java函數關鍵點及示例 http://blog.csdn.net/fu_shuwu/article/details/41121741 3 http://blog.cs…

signature=f7a4b29b93ef2b36608792fdef7f454a,Embedding of image authentication signatures

摘要&#xff1a;A method (), an apparatus, a computer readable medium and use of said method for authenticating an audio-visual signal (), such as a digital image or video, are disclosed. A signature is derived from all image regions, including areas with …

glob

主要是用來在匹配文件&#xff0c;相當shell中用通配符匹配. 用法: glob.glob(pathname) # 返回匹配的文件作為一個列表返回 glob.iglob(pathname) # 匹配到的文件名&#xff0c;返回一個迭代器 ps: pathname是路徑, 可以是絕對和相對路徑 匹配當前目錄下有一個數字開頭…

構建微服務:Spring boot 入門篇

Spring官方網站本身使用Spring框架開發&#xff0c;隨著功能以及業務邏輯的日益復雜&#xff0c;應用伴隨著大量的XML配置文件以及復雜的Bean依賴關系。隨著Spring 3.0的發布&#xff0c;Spring IO團隊逐漸開始擺脫XML配置文件&#xff0c;并且在開發過程中大量使用“約定優先配…

img 加載 svg占位符_如何使用SVG作為占位符以及其他圖像加載技術

img 加載 svg占位符by Jos M. Prez由JosM.Prez 如何使用SVG作為占位符以及其他圖像加載技術 (How to use SVG as a Placeholder, and Other Image Loading Techniques) I’m passionate about image performance optimisation and making images load fast on the web. One of…

hibernate 注解

參考鏈接地址&#xff1a;https://blog.csdn.net/wx5040257/article/details/78697119 主鍵生成策略:https://www.cnblogs.com/ph123/p/5692194.html 注解轉載于:https://www.cnblogs.com/wangxuekui/p/10287647.html

iOS - UIScrollView

前言 NS_CLASS_AVAILABLE_IOS(2_0) interface UIScrollView : UIView <NSCoding>available(iOS 2.0, *) public class UIScrollView : UIView, NSCoding 移動設備的屏幕大小是極其有限的&#xff0c;因此直接展示在用戶眼前的內容也相當有限。當展示的內容較多&…

機器學習的展望

現階段越來越多的投入到機器學習的熱潮中來&#xff0c;有的人很是興奮&#xff0c;認為這是一場新和革命&#xff0c;一場終極人工智能來臨的前夜。也有人表示悲觀&#xff0c;認為不僅機器學習不代表終極人工智能&#xff0c; 也還非常不成熟。 大量的新生代投入到這個領域&a…

BZOJ3453 XLkxc(拉格朗日插值)

顯然f(i)是一個k2項式&#xff0c;g(x)是f(i)的前綴和&#xff0c;則顯然其是k3項式&#xff0c;插值即可。最后要求的東西大膽猜想是個k4項式繼續插值就做完了。注意2p>maxint…… #include<iostream> #include<cstdio> #include<cmath> #include<cs…

電郵地址_利用這些簡單的技巧來充分利用電子郵件的強大功能

電郵地址Let’s talk about some email features that are surprisingly under-used, and that can really benefit you — if you know how to use them. This article is suitable for both users and developers who want to become email Jedi.讓我們討論一些電子郵件功能&…

inputstream重新賦值之前需要close嗎_變量提升真的搞懂了嗎?打臉的一道題

變量提升真的搞懂了嗎&#xff1f;打臉的一道題我們知道JS代碼在執行之前&#xff0c;會做一系列的事情&#xff0c;其中就包括變量提升&#xff0c;原本以為把變量提升搞懂的我&#xff08;因為這兩天一直在研究變量提升&#xff0c;自我感覺已經很良好了&#xff0c;哈哈哈&a…

html5語義化 兼容,HTML5語義化標簽,兼容性問題

HTML5不僅僅作為HTML標記語言的一個最新版本&#xff0c;更重要的是它制定了web應用開發的一系列標準&#xff0c;成為第一個將web做為應用開發平臺的HTML語言。HTML5定義了一系列的新元素&#xff0c;如新語義化標簽&#xff0c;智能表單&#xff0c;多媒體標簽等&#xff0c;…

Swift之 vm10虛擬機安裝Mac OS X10.10教程

VM10裝Mac OS X 10.9.3及更新到Mac OS X 10.10,讓你的windows也能玩Swift 。 近期WWDC放出終極大招——新的編程語言Swift(雨燕),導致一大波程序猿的圍觀和躍躍欲試。當然了,工欲善其事,必先利其器,所以對于那些沒有Mac又想要嘗鮮的小伙伴肯定非常為難。可是&#xff0c;請放…

如何使用json開發web_如何通過使用JSON Web令牌簡化應用程序的身份驗證

如何使用json開發webby Sudheesh Shetty由Sudheesh Shetty 如何通過使用JSON Web令牌簡化應用程序的身份驗證 (How to simplify your app’s authentication by using JSON Web Token) Every application we come across today implements security measures so that the user…

c++ 實現錄音并且指定到文件_通話自動錄音,留下美好回憶,記錄完整錄音證據...

手機通話&#xff0c;如果自動錄音多好&#xff0c;許多人與我一樣抱有這個想法。記得華為Android版本5.0時代&#xff0c;手機沒有自動錄音功能&#xff0c;我一直到網上下載自動通話錄音軟件&#xff0c;有時甚至是下載ROOT版的帶自動通話功能的EMUI版本進行刷機安裝。那個時…