Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Aspect Oriented Programming
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Weizhong Yang
September 12, 2013
Technology
280
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Aspect Oriented Programming
Weizhong Yang
September 12, 2013
More Decks by Weizhong Yang
See All by Weizhong Yang
導入 Flutter 前你應該知道的事
zonble
7
1.3k
那些年,被蘋果 Ban 掉的 API
zonble
0
210
為視障朋友打造行動應用
zonble
16
1.4k
Mac OS X 與 iOS 的 Audio API
zonble
11
1.1k
大家來寫貪食蛇
zonble
7
4.5k
Debug Debug
zonble
6
470
Retina Mac
zonble
3
300
HTML 5 Native Drag
zonble
3
570
Other Decks in Technology
See All in Technology
AI時代、つくる力を自分たちの手に。 ──電通×KAG、アジャイルとAI駆動開発で挑む開発の変革
yuukiyo
3
420
Flutter Widget Previewerで始めるUIプレビューとVRTの自動化
sakusaku3939
0
170
AI時代のエンジニアの情報発信〜個人の発信を組織の力に変える〜
ryo_kawamata
0
370
ガチで放置できるClaude Code実行環境の作り方.pdf
lamaglama39
5
10k
自律的なチームを作るためにTechPMがやらないこと
ny7760
0
130
あなたのDartコードは丸見えかもしれない ~reFlutterで暴くFlutterアプリの中身と多層防御~
zozotech
PRO
0
590
渡米前の準備を制す!re:Invent 2026徹底準備術 / The Ultimate Preparation Guide for re:Invent 2026
yuj1osm
1
400
AI時代の開発はウォーターフォールに回帰する? / development-with-ai-back-to-wf
okamototakuyasr2
0
150
正解のない研修に放り出されて / Being thrown into a training program with no right answers
ohnoeight
1
170
これだけは抑えておきたい!後悔しない re:Invent の過ごし方 / AWS re:Invent 2026 prestudy
kinunori
2
550
Lint の層を組み直した話
bengo4com
1
180
Autonomous AI Lakehouse - Live AI Hubから始めるセキュアなAIデータ活用 -
oracle4engineer
PRO
2
170
Featured
See All Featured
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
410
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
300
Building AI with AI
inesmontani
PRO
1
1.3k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
340
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.5k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
340
Bash Introduction
62gerente
615
220k
Leo the Paperboy
mayatellez
10
2.4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.4k
Building the Perfect Custom Keyboard
takai
2
930
Transcript
Aspect Oriented Programming 楊維中 a.k.a zonble
[email protected]
Thursday, September 12,
zonble ฌᖯ؛ۇ Thursday, September 12,
ᖯ৵ʔ݊ɓ˂ிϓٙ Unmaintainable 的 code 也是 Thursday, September 12,
⼀一開始,程式邏輯就只有插 ⼊入資料⽽而已… - (void)appendData:(NSData *)inData { [_data appendData:inData]; } Thursday,
September 12,
後來,我們想確定傳⼊入的不 是 nil 或空資料 - (void)appendData:(NSData *)inData { NSParameterAssert(inData !=
nil); NSParameterAssert([inData length]); length = [_data length]; [_data appendData:inData]; NSAssert(length != [_data length]); } Thursday, September 12,
後來,我們覺得 Release Build 也應該防⽌止輸⼊入空資料… - (void)appendData:(NSData *)inData { NSParameterAssert(inData !=
nil); NSParameterAssert([inData length]); if (!inData) { return; } if (![inData length]) { return; } length = [_data length]; [_data appendData:inData]; NSAssert(length != [_data length]); } Thursday, September 12,
後來,我們發現這個 method 可能會在很多 thread 呼叫… - (void)appendData:(NSData *)inData { NSParameterAssert(inData
!= nil); NSParameterAssert([inData length]); if (!inData) { NSLog(@"inData is nil!"); return; } if (![inData length]) { NSLog(@"Length of inData is 0!"); return; } length = [_data length]; [_lock lock]; [_data appendData:inData]; [_lock unlock]; NSAssert(length != [_data length]); } Thursday, September 12,
後來,在 Debug Build 裡頭要 加上 TestFlight CheckPoint - (void)appendData:(NSData *)inData
{ NSParameterAssert(inData != nil); NSParameterAssert([inData length]); if (!inData) { NSLog(@"inData is nil!"); return; } if (![inData length]) { NSLog(@"Length of inData is 0!"); return; } length = [_data length]; [_lock lock]; [_data appendData:inData]; [_lock unlock]; NSAssert(length != [_data length]); #if DEBUG [TestFlight passCheckpoint:@"APPEND_DATA"]; #endif } Thursday, September 12,
Release Build 則要加上 Flurry Event Log… - (void)appendData:(NSData *)inData {
NSParameterAssert(inData != nil); NSParameterAssert([inData length]); if (!inData) { NSLog(@"inData is nil!"); return; } if (![inData length]) { NSLog(@"Length of inData is 0!"); return; } length = [_data length]; [_lock lock]; [_data appendData:inData]; [_lock unlock]; NSAssert(length != [_data length]); #if DEBUG [TestFlight passCheckpoint:@"APPEND_DATA"]; #else [Flurry logEvent:@"APPEND_DATA"]; #endif } Thursday, September 12,
還有 Google Analytics… - (void)appendData:(NSData *)inData { NSParameterAssert(inData != nil);
NSParameterAssert([inData length]); if (!inData) { NSLog(@"inData is nil!"); return; } if (![inData length]) { NSLog(@"Length of inData is 0!"); return; } length = [_data length]; [_lock lock]; [_data appendData:inData]; [_lock unlock]; NSAssert(length != [_data length]); #if DEBUG [TestFlight passCheckpoint:@"APPEND_DATA"]; #else [Flurry logEvent:@"APPEND_DATA"]; id<GAITracker>tracker = [[GAI sharedInstance] defaultTracker]; [tracker send: [[GAIDictionaryBuilder createEventWithCategory:@"data" withAction:@"append" withLabel:@"user_data" withValue:nil] build]]; #endif } Thursday, September 12,
每件事情都很重要 • 確定傳⼊入參數的型態與內容 • 確定真的有插⼊入資料 • 加 Lock • 加
Debug Log • 加 TestFlight Log、Flurry Log… Thursday, September 12,
23 ⾏行 code 中, ਂ͍ԫ̥ٙϞɓБf 這還不是最糟的… Thursday, September 12,
更糟的是… 不只⼀一個 method 這樣 Thursday, September 12,
ᒔึॎᕸόٙࠠ͜ Thursday, September 12,
上個世紀末,就有⼈人覺得… வᅵʔБ 接下來的故事請⾃自⼰己查 Wikipedia Thursday, September 12,
AOP 的基本想法: Ҫ၇ౢආԸٙ Code פᕎԨ܆ༀ ⽅方法很多 Thursday, September 12,
Cross-cutting concerns …就是這些 • 確定傳⼊入參數的型態與內容 • 確定真的有插⼊入資料 • 加 Lock
• 加 Debug Log • 加 TestFlight Log、Flurry Log… Thursday, September 12,
Advice 在原本程式前後 插⼊入的程式碼 Thursday,
September 12,
Decorator Syntax …Objective C 不⽀支援 Thursday, September 12,
Decorator Syntax def add(x): print "x:" + str(x) result =
x + 1 print "result:" + str(result) return result Thursday, September 12,
Decorator Syntax def log(func): def inner_func(*a): print "args:" + str(a)
result = func(*a) print "result:" + str(result) return inner_func @log def add(x): return x + 1 Thursday, September 12,
Objective-C 特性 Message Forwarding 當⼀一個物件不⽀支援某個 Selector 的時 候,這個物件可以決定把 Selector 交給
其他的物件。 Thursday, September 12,
Message Forwarding - (void)forwardInvocation:(NSInvocation *)anInvocation { if ([someOtherObject respondsToSelector: [anInvocation
selector]]) // Advice here [anInvocation invokeWithTarget:someOtherObject]; // Advice here else [super forwardInvocation:anInvocation]; } See: Objective-C Runtime Programming Guide Thursday, September 12,
AOP-in-Objective-C https://github.com/moszi/AOP-in- Objective-C Thursday, September 12,
Method Swizzling Thursday, September 12,
Objective-C 第⼀一課 • ObjC 物件都是 C Structure • ObjC method
都是 C function pointer • 系統有⼀一個動態的索引表格,決定執⾏行 某個 selector 時,要對應到哪個 C function • Selector 就是索引表中的 key,型態為 C 字串 Thursday, September 12,
Objective-C 第⼆二課 • ⼀一個 Class 有哪些 method,都是在 runtime 的時候建⽴立的 •
所以可以在 runtime 新增新的 method, 例如使⽤用 category 語法 • 也可以直接使⽤用 runtime API 把已經存在 的 method 換掉 Thursday, September 12,
<objc/runtime.h> BOOL class_addMethod(Class cls, SEL name, IMP imp, const char
*types); IMP method_setImplementation(Method method, IMP imp); Thursday, September 12,
Thursday, September 12,
Thursday, September 12,
Thursday, September 12,
AOP-for-Objective-C https://github.com/ndcube/AOP-for- Objective-C/ 在繼承關係的部份有些 bug,我⾃自⼰己有 先修,但是還沒有送 pull request… Thursday, September
12,
Thank you! Thursday, September 12,