SlideShare a Scribd company logo
Object Oriented Programming
in Swift
Ch 0
Sai Li @ Yowoo Tech.
2016/11/18
References
References
• Agile Software Development: Principles, Patterns,
and Practice ( : )

by Robert C. Martin
References
• Agile Software Development: Principles, Patterns,
and Practice ( : )

by Robert C. Martin
• Fundamental Object Oriented Programming 

by Hsuan-Tien Lin
References
• Agile Software Development: Principles, Patterns,
and Practice ( : )

by Robert C. Martin
• Fundamental Object Oriented Programming 

by Hsuan-Tien Lin
• 

by Teddy Chen
References
• Agile Software Development: Principles, Patterns,
and Practice ( : )

by Robert C. Martin
• Fundamental Object Oriented Programming 

by Hsuan-Tien Lin
• 

by Teddy Chen
• Essential Object-Oriented Programming

by Josh Ko
Language
• Java
• Python
• Swift
How to build an
iPhone?
Object Oriented Programming in Swift Ch0 - Encapsulation
System -> Components
System -> Components
Divide and Conquer
System -> Components
Divide and Conquer
Modularization
Good Modules make good System
Good Modules make good System
• Easy to debug
Good Modules make good System
• Easy to debug
• Easy to maintain/ manage
Good Modules make good System
• Easy to debug
• Easy to maintain/ manage
• Easy to modify/ update
Good Modules make good System
• Easy to debug
• Easy to maintain/ manage
• Easy to modify/ update
• Easy to reuse
Good Modules make good System
• Easy to debug
• Easy to maintain/ manage
• Easy to modify/ update
• Easy to reuse
Good Modules make good System
• Easy to debug
• Easy to maintain/ manage
• Easy to modify/ update
• Easy to reuse
Modularization: Save time in the future
Save money, save time

No more disposable programs
Spaghetti Code
Spaghetti Code
Edible is enough
Spaghetti Code
Spaghetti Code
Noodle Oriented
Programming
Noodle -> Procedure
• More organized than spaghetti code
• Identify the purpose
• Isolate (modularize)
• Reuse
Noodle -> Procedure
• More organized than spaghetti code
• Identify the purpose
• Isolate (modularize)
• Reuse
C language
OOP
• Grouped related data
OOP
• Use Struct/ Class to generate objects
OOP
• Don’t do something on the object
• Let object takes actions
OOP
• Don’t do something on the object
• Let object takes actions
OOP
• Don’t do something on the object
• Let object takes actions
Noodles -> Procedure -> Object
• NOP: spaghetti code + (possibly spaghetti) data

Assembly
Noodles -> Procedure -> Object
• NOP: spaghetti code + (possibly spaghetti) data

Assembly
• POP: organized code + (possibly organized) data

C, PASCAL

basic modules: procedures
Noodles -> Procedure -> Object
• NOP: spaghetti code + (possibly spaghetti) data

Assembly
• POP: organized code + (possibly organized) data

C, PASCAL

basic modules: procedures
• OOP: organized code + organized data (grouped)

Swift, Java, Python

basic modules: Class / Struct
Noodles -> Procedure -> Object
OO Levels
OO Levels
• OO Analysis:

what the system does
OO Levels
• OO Analysis:

what the system does
• needs -> models
OO Levels
• OO Analysis:

what the system does
• needs -> models
• Software Engineering
OO Levels
• OO Analysis:

what the system does
• needs -> models
• Software Engineering
• OO Design:

how the system dose it
OO Levels
• OO Analysis:

what the system does
• needs -> models
• Software Engineering
• OO Design:

how the system dose it
• model -> class diagrams
OO Levels
• OO Analysis:

what the system does
• needs -> models
• Software Engineering
• OO Design:

how the system dose it
• model -> class diagrams
• Design Pattern
OO Levels
• OO Analysis:

what the system does
• needs -> models
• Software Engineering
• OO Design:

how the system dose it
• model -> class diagrams
• Design Pattern
• OO Programming

how to implement it
OO Levels
• OO Analysis:

what the system does
• needs -> models
• Software Engineering
• OO Design:

how the system dose it
• model -> class diagrams
• Design Pattern
• OO Programming

how to implement it
• class diagrams -> implementations
OO Levels
• OO Analysis:

what the system does
• needs -> models
• Software Engineering
• OO Design:

how the system dose it
• model -> class diagrams
• Design Pattern
• OO Programming

how to implement it
• class diagrams -> implementations
• OOP, this one
How to build an
iPhone?
Decomposition
Decomposition
System
Decomposition
System
object
objectobject
Decomposition
System
abstraction
object
objectobject
Decomposition
System
abstraction
object
objectobject
Decomposition
System
abstraction
object
Modeling
objectobject
Data Abstraction
Object
Data Abstraction
Object
method
Data Abstraction
Object
method
Data Abstraction
Object
method
Data Abstraction
Object
method
Interface
Data Abstraction
Object
method
Interface
Implementation
Data Abstraction
Abstraction is selective ignorance.
by Andrew Koenig
Data Abstraction
Abstraction is selective ignorance.
by Andrew Koenig
Others care about the interface and
ignore the implementation
Encapsulation
Access Control: public and private
Encapsulation
Access Control: public and private
Encapsulation
Access Control: public and private
Design by Contract
Design by Contract
• Class Invariant
Design by Contract
• Class Invariant
• Valid State
Design by Contract
• Class Invariant
• Valid State
Design by Contract
• Class Invariant
• Valid State
private(set)
private(set)
Design by Contract
• Class Invariant
• Valid State
• 1 <= day <= 31

0 <= hour <= 24
private(set)
private(set)
Design by Contract
• Preconditions, postconditions
Design by Contract
• Preconditions, postconditions
First class invariant ?
Design by Contract
• Preconditions, postconditions
First class invariant ?
Constructor
Object Oriented Programming in Swift Ch0 - Encapsulation
Object Oriented Programming in Swift Ch0 - Encapsulation
Object Oriented Programming in Swift Ch0 - Encapsulation
Object Oriented Programming in Swift Ch0 - Encapsulation
Object Oriented Programming in Swift Ch0 - Encapsulation
Object Oriented Programming in Swift Ch0 - Encapsulation
Object Oriented Programming in Swift Ch0 - Encapsulation
Object Oriented Programming in Swift Ch0 - Encapsulation
Encapsulation
• Separate implementation and use
Encapsulation
• Separate implementation and use
• Don’t trust other people including you(3 months after)
Encapsulation
• Separate implementation and use
• Don’t trust other people including you(3 months after)
• Hide unnecessary details
Encapsulation
• Separate implementation and use
• Don’t trust other people including you(3 months after)
• Hide unnecessary details
• One more oz
Encapsulation
• Separate implementation and use
• Don’t trust other people including you(3 months after)
• Hide unnecessary details
• One more oz
Encapsulation
• Separate implementation and use
• Don’t trust other people including you(3 months after)
• Hide unnecessary details
• One more oz
Think about incorrect use about your class
Encapsulation
As a designer,
you should avoid giving the users of your
code too much freedom to do bad and/or
make bugs
Object Oriented Programming in Swift Ch0 - Encapsulation
Object Oriented Programming in Swift Ch0 - Encapsulation
accessor (getter)
accessor (getter)
accessor (getter)
mutator (setter)
OOP
• Encapsulation: Security
• Inheritance: Reusability
• Polymorphism: Flexibility
Q & A

To be continued…
References
References
• Agile Software Development: Principles, Patterns, and Practice (
: )
References
• Agile Software Development: Principles, Patterns, and Practice (
: )
• Fundamental Object Oriented Programming
References
• Agile Software Development: Principles, Patterns, and Practice (
: )
• Fundamental Object Oriented Programming
•
References
• Agile Software Development: Principles, Patterns, and Practice (
: )
• Fundamental Object Oriented Programming
•
• Essential Object-Oriented Programming
References
• Agile Software Development: Principles, Patterns, and Practice (
: )
• Fundamental Object Oriented Programming
•
• Essential Object-Oriented Programming
• images.techtimes.com/data/images/full/11234/tangled-earbuds.jpg
References
• Agile Software Development: Principles, Patterns, and Practice (
: )
• Fundamental Object Oriented Programming
•
• Essential Object-Oriented Programming
• images.techtimes.com/data/images/full/11234/tangled-earbuds.jpg
• spaghetticrunch.com/wp-content/uploads/2014/12/spaghetti-
bolognaise-1.png
References
• Agile Software Development: Principles, Patterns, and Practice (
: )
• Fundamental Object Oriented Programming
•
• Essential Object-Oriented Programming
• images.techtimes.com/data/images/full/11234/tangled-earbuds.jpg
• spaghetticrunch.com/wp-content/uploads/2014/12/spaghetti-
bolognaise-1.png
• upload.wikimedia.org/wikipedia/commons/thumb/e/ea/
Design_by_contract.svg/220px-Design_by_contract.svg.png
References
• Agile Software Development: Principles, Patterns, and Practice (
: )
• Fundamental Object Oriented Programming
•
• Essential Object-Oriented Programming
• images.techtimes.com/data/images/full/11234/tangled-earbuds.jpg
• spaghetticrunch.com/wp-content/uploads/2014/12/spaghetti-
bolognaise-1.png
• upload.wikimedia.org/wikipedia/commons/thumb/e/ea/
Design_by_contract.svg/220px-Design_by_contract.svg.png
• www.linuxdigest.org/wp-content/uploads/2012/06/09fig091.gif

More Related Content

PDF
PPTX
ORMs Meet SQL
PDF
Object Oriented Programming in Swift Ch1 - Inheritance
PPT
20. Object-Oriented Programming Fundamental Principles
PPTX
Swift as an OOP Language
PPTX
Session 1. iOS developers enthusiasts session
PDF
An introduction to functional programming with Swift
PDF
Agile Development: Scrum introduction
ORMs Meet SQL
Object Oriented Programming in Swift Ch1 - Inheritance
20. Object-Oriented Programming Fundamental Principles
Swift as an OOP Language
Session 1. iOS developers enthusiasts session
An introduction to functional programming with Swift
Agile Development: Scrum introduction

Viewers also liked (16)

PPTX
_Base: ¡5 posiciones! -Pasar y cortar- (Parte 1)
PDF
Design Engineering 1A Report Template
DOCX
mathematics and intelligence
PDF
Taller Swift - iCon
PDF
놀아요 Swift Playgrounds
PDF
Feedback on Part 1 of the CSLP
PDF
Testing Android apps with Robotium
PDF
Swift Tutorial 2
PDF
Swift Tutorial 1
PDF
Common Java problems when developing with Android
PDF
Getting started with Xcode
PDF
Crash Course in Objective-C
PDF
Feedback on Part 1 of the Software Engineering Large Practical
PDF
METODE PELAKSANAAN DAN EVALUASI JALAN
PDF
Programming in Objective-C
PDF
Standford 2015 iOS讀書會 week1: 1.Logistics , iOS 8 Overview 2. More Xcode and S...
_Base: ¡5 posiciones! -Pasar y cortar- (Parte 1)
Design Engineering 1A Report Template
mathematics and intelligence
Taller Swift - iCon
놀아요 Swift Playgrounds
Feedback on Part 1 of the CSLP
Testing Android apps with Robotium
Swift Tutorial 2
Swift Tutorial 1
Common Java problems when developing with Android
Getting started with Xcode
Crash Course in Objective-C
Feedback on Part 1 of the Software Engineering Large Practical
METODE PELAKSANAAN DAN EVALUASI JALAN
Programming in Objective-C
Standford 2015 iOS讀書會 week1: 1.Logistics , iOS 8 Overview 2. More Xcode and S...
Ad

Similar to Object Oriented Programming in Swift Ch0 - Encapsulation (20)

PPTX
PATTERNS01 - An Introduction to Design Patterns
PPTX
SAD02 - Object Orientation
PPT
chapter 5 Objectdesign.ppt
PPT
Oomd unit1
PPTX
CPP16 - Object Design
PPTX
Clean code presentation
PPTX
Object Oriented, Design patterns and data modelling worshop
PPTX
Software_Engineering_Presentation (1).pptx
PDF
Introduction to Object Oriented Programming &amp; Design Principles
PPT
Unit 1( modelling concepts & class modeling)
PPTX
Concepts of oops
PDF
Introduction to Object Oriented Programming & Design Principles
PPT
Design poo my_jug_en_ppt
PPTX
Assignment 1 SYD601 2012 rick_danby completed with audio
DOCX
Unit1 jaava
DOCX
Ooad unit 1
PPTX
OO design slide
PPTX
Software Design
PPTX
Clean code
PPT
Software Engineering Systems Designing end to end
PATTERNS01 - An Introduction to Design Patterns
SAD02 - Object Orientation
chapter 5 Objectdesign.ppt
Oomd unit1
CPP16 - Object Design
Clean code presentation
Object Oriented, Design patterns and data modelling worshop
Software_Engineering_Presentation (1).pptx
Introduction to Object Oriented Programming &amp; Design Principles
Unit 1( modelling concepts & class modeling)
Concepts of oops
Introduction to Object Oriented Programming & Design Principles
Design poo my_jug_en_ppt
Assignment 1 SYD601 2012 rick_danby completed with audio
Unit1 jaava
Ooad unit 1
OO design slide
Software Design
Clean code
Software Engineering Systems Designing end to end
Ad

More from Chihyang Li (20)

PDF
Image Style Transfer and AI on iOS Mobile App
PDF
Image style transfer and iOS CoreML, Vision Frameworks
PDF
Machine Learning in Swift
PDF
Image style transfer & AI on App
PDF
iOS Vision framework
PDF
Design Patterns in Swift Ch5 Abstract Factory Builder
PDF
Design patterns in Swift Ch4: Iterator & Template Method
PDF
Swift map & flatMap
PDF
Swift Optional ??
PDF
Design Pattern in Swift Ch2 Strategy, Decorator
PDF
Design Pattern Ch3 in Swift Composite
PDF
Design Patterns in Swift Ch1 Factory Method
PDF
Scrum & Kanban Introduction
PDF
Design Patterns in Swift ch0 Introduction
PDF
Object Oriented Programming Ch3 SRP, DIP, ISP
PDF
Object Oriented Programming in Swift Ch2 Polymorphism, OCP, LSP
PDF
Apple Swift API Design Guideline
PDF
Swift capture
PDF
DevOps 2016 summit
PDF
Slack introduction
Image Style Transfer and AI on iOS Mobile App
Image style transfer and iOS CoreML, Vision Frameworks
Machine Learning in Swift
Image style transfer & AI on App
iOS Vision framework
Design Patterns in Swift Ch5 Abstract Factory Builder
Design patterns in Swift Ch4: Iterator & Template Method
Swift map & flatMap
Swift Optional ??
Design Pattern in Swift Ch2 Strategy, Decorator
Design Pattern Ch3 in Swift Composite
Design Patterns in Swift Ch1 Factory Method
Scrum & Kanban Introduction
Design Patterns in Swift ch0 Introduction
Object Oriented Programming Ch3 SRP, DIP, ISP
Object Oriented Programming in Swift Ch2 Polymorphism, OCP, LSP
Apple Swift API Design Guideline
Swift capture
DevOps 2016 summit
Slack introduction

Recently uploaded (20)

PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
System and Network Administration Chapter 2
PPT
Introduction Database Management System for Course Database
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Introduction to Artificial Intelligence
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Understanding Forklifts - TECH EHS Solution
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PTS Company Brochure 2025 (1).pdf.......
ManageIQ - Sprint 268 Review - Slide Deck
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
2025 Textile ERP Trends: SAP, Odoo & Oracle
Softaken Excel to vCard Converter Software.pdf
System and Network Administration Chapter 2
Introduction Database Management System for Course Database
Upgrade and Innovation Strategies for SAP ERP Customers
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How Creative Agencies Leverage Project Management Software.pdf
CHAPTER 2 - PM Management and IT Context
Introduction to Artificial Intelligence
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Understanding Forklifts - TECH EHS Solution
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Wondershare Filmora 15 Crack With Activation Key [2025
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf

Object Oriented Programming in Swift Ch0 - Encapsulation