SlideShare a Scribd company logo
1 of 19
Download to read offline
Switch/Case
Fika Time

zonble
很多時候你不該⽤用
Boolean,⽽而是 Enum
你真的需要
這麼多 Boolean 嗎?
其實你需要的是 Enum
其實你需要的是 Enum
• ⼀一起聽只有:未連線、台長、聽眾,三種狀狀態

• ⽤用三個 Bool 會變成八種狀狀態,但有五種狀狀態不可能出現

• 如果進入這五種狀狀態,就是 Bug
⼀一個需要分段載入的畫⾯面
⽤用了了多個 Bool 表⽰示「是否初次載入」、
「是否載入中」、「是否還需要改入更更多資料」…
⼀一個需要分段載入的畫⾯面
需求往往不是⼀一次提出來來的…
• ⼀一開始沒做載入中動畫,為了了呈現載入進度,所以多⼀一個
Bool 判斷…

• ⼀一開始沒做錯誤處理理,為了了呈現錯誤,所以多⼀一個 Bool 判
斷…

• ⼀一開始沒做 Empty Set,所以多⼀一個 Bool 判斷…

• 但,放任歷史的遺跡殘留留,就會讓程式碼失控
UI Stack
•Ideal State
•Empty State
•Error State
•Partial State
•Loading State
⼀一個需要分段載入的畫⾯面
加上⼀一點 Swift 特性
⼀一個需要分段載入的畫⾯面
⼀一個需要分段載入的畫⾯面
測試 case 也好寫了了
• 測試某些 Action 是否會讓畫⾯面進入某個 State

• 測試某個 State 下 Layout 出來來的畫⾯面是否符合預期
歌曲辨識
其實就是:
Empty State
Loading State
Ideal State
Error State
什什麼可以⽤用
Switch/Case 改寫?
FizzBuzz
根據不同時段給不同圖片
Tuple

More Related Content

What's hot

What's hot (20)

Jetpack Compose - Android’s modern toolkit for building native UI
Jetpack Compose - Android’s modern toolkit for building native UIJetpack Compose - Android’s modern toolkit for building native UI
Jetpack Compose - Android’s modern toolkit for building native UI
 
Jetpack compose
Jetpack composeJetpack compose
Jetpack compose
 
Spring aop
Spring aopSpring aop
Spring aop
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
以 Kotlin Multiplatform Mobile (KMM) 開發跨平台行動應用
以 Kotlin Multiplatform Mobile (KMM) 開發跨平台行動應用以 Kotlin Multiplatform Mobile (KMM) 開發跨平台行動應用
以 Kotlin Multiplatform Mobile (KMM) 開發跨平台行動應用
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
 
Lessons-Learned-SwiftUI.pptx
Lessons-Learned-SwiftUI.pptxLessons-Learned-SwiftUI.pptx
Lessons-Learned-SwiftUI.pptx
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack Compose
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 
Spring framework core
Spring framework coreSpring framework core
Spring framework core
 
[JCConf 2022] Compose for Desktop - 開發桌面軟體的新選擇
[JCConf 2022] Compose for Desktop - 開發桌面軟體的新選擇[JCConf 2022] Compose for Desktop - 開發桌面軟體的新選擇
[JCConf 2022] Compose for Desktop - 開發桌面軟體的新選擇
 
React Native
React NativeReact Native
React Native
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
Java Spring
Java SpringJava Spring
Java Spring
 
Testing with Spring: An Introduction
Testing with Spring: An IntroductionTesting with Spring: An Introduction
Testing with Spring: An Introduction
 
Create-React-App으로 SSR을 구현하며 배운 점 (feat. TypeScript)
Create-React-App으로 SSR을 구현하며 배운 점 (feat. TypeScript)Create-React-App으로 SSR을 구현하며 배운 점 (feat. TypeScript)
Create-React-App으로 SSR을 구현하며 배운 점 (feat. TypeScript)
 
Android jetpack compose | Declarative UI
Android jetpack compose | Declarative UI Android jetpack compose | Declarative UI
Android jetpack compose | Declarative UI
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelines
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 

More from Weizhong Yang

苦集滅道:透過開發客製 Sketch Plug-in 改善產品設計流程
苦集滅道:透過開發客製 Sketch Plug-in  改善產品設計流程苦集滅道:透過開發客製 Sketch Plug-in  改善產品設計流程
苦集滅道:透過開發客製 Sketch Plug-in 改善產品設計流程
Weizhong Yang
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
Weizhong Yang
 
Python 的文件系統
Python 的文件系統Python 的文件系統
Python 的文件系統
Weizhong Yang
 

More from Weizhong Yang (20)

Flutter BLE
Flutter BLEFlutter BLE
Flutter BLE
 
怎樣在 Flutter app 中使用 Google Maps
怎樣在 Flutter app 中使用 Google Maps怎樣在 Flutter app 中使用 Google Maps
怎樣在 Flutter app 中使用 Google Maps
 
關於延長役期這件事情
關於延長役期這件事情關於延長役期這件事情
關於延長役期這件事情
 
Dart null safety
Dart null safetyDart null safety
Dart null safety
 
導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事
 
Github Actions
Github ActionsGithub Actions
Github Actions
 
iPlayground: CarPlay and MFI Hearing Aids
iPlayground: CarPlay and MFI Hearing AidsiPlayground: CarPlay and MFI Hearing Aids
iPlayground: CarPlay and MFI Hearing Aids
 
CocoaPods private repo
CocoaPods private repoCocoaPods private repo
CocoaPods private repo
 
Flutter 踩雷心得
Flutter 踩雷心得Flutter 踩雷心得
Flutter 踩雷心得
 
那些年被蘋果 Ban 掉的 API
那些年被蘋果 Ban 掉的 API那些年被蘋果 Ban 掉的 API
那些年被蘋果 Ban 掉的 API
 
苦集滅道:透過開發客製 Sketch Plug-in 改善產品設計流程
苦集滅道:透過開發客製 Sketch Plug-in  改善產品設計流程苦集滅道:透過開發客製 Sketch Plug-in  改善產品設計流程
苦集滅道:透過開發客製 Sketch Plug-in 改善產品設計流程
 
怎樣寫出比較沒有問題的 Code
怎樣寫出比較沒有問題的 Code怎樣寫出比較沒有問題的 Code
怎樣寫出比較沒有問題的 Code
 
貪食蛇
貪食蛇貪食蛇
貪食蛇
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
 
Mac OS X 與 iOS 的 Audio API
Mac OS X 與 iOS 的 Audio APIMac OS X 與 iOS 的 Audio API
Mac OS X 與 iOS 的 Audio API
 
Html 5 native drag
Html 5 native dragHtml 5 native drag
Html 5 native drag
 
Retina mac
Retina macRetina mac
Retina mac
 
Python 的文件系統
Python 的文件系統Python 的文件系統
Python 的文件系統
 
Refactoring
RefactoringRefactoring
Refactoring
 
Core animation
Core animationCore animation
Core animation
 

使用 switch/case 重構程式碼