SlideShare a Scribd company logo
Object Oriented Programming
in Swift
Ch 1: Inheritance
Sai Li @ Yowoo Tech.
2016/12/5
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
OOP
• Encapsulation
• Inheritance
• Polymorphism
Spaghetti
v.s
Ravioli
Inheritance
Has-A
• Has-A: a basic way to reuse variables/methods
in other classes
Has-A
• Has-A: a basic way to define components of a system
• iPhone has a camera
Has-A
• Has-A: a basic mechanism for
objects to connect with each other
• He has 2 friends: Tom and Jerry
Has-A: most basic design component of OOP
chi
• Admin is a user
• can be implemented via has-a:

Everyone has Brokeback Mountain in mind
child
• Type A inherit TypeB: TypeA is a (special case of) TypeB
• TypeSubClass (TypeDerivedClass or ChildClass) inherit

TypeSuperClass (TypeBaseClass or ParentClass)
is-a != has-a
Uses of Is-A
• CDAndCassetePlayer is a CassettePlayer
Uses of Is-A
• CassettePlayer is a (concrete type of) Player
• CDPlayer is a (concrete type of) Player
Uses of Is-A
• CDplayer is a (update of) CassettePlayer
• some behaviors “changed”
• no as clear as the previous case, but a potential trick
in OOP
• Multiple inheritance: Not supported in Swift
• Swift: single inheritance (Java)
Diamond Problem
?
Diamond Problem
Is-A
• is an extended type of

- FunPerson is Person who can tell jokes
• is a more concrete/restricted description of 

- YoungPerson is Person who is young
• (is an update of)

- NewStaff replaces ExistingStaff
Object Oriented Programming in Swift Ch1 - Inheritance
• Over-use of inherit for is-a: 1 class -> 1 instance
• Usual goal of OOP: one class, many instances
Is-A
• Under-user of inherit for is-a: overly complicated class
YowooStaff
• Bugs/hacks?

cali = YowooStaff(id: “”, name: “CYLi”, title: “CFO”)
Terminology
Instance Variables and Inheritance
• Staff: 1 instance variables
• YowooStaff: 2 instance variables
Instance Variables and Inheritance
• instance variable binding: determined at
compile time
• same “name” can NOT co-exist in a class,
binding determined by compile-time type.
Instance Methods and Inheritance
• Staff: 1 instance method
• RD: 2 instance methods
• what output?
• instance method binding: dynamic, depending
on run-time instance types
Reference Assignment
• saiLi is an instance of GoodStudent
• saiLi is an instance of Student, too
• one instance, many coherent types
Constructor and Inheritance
• initialize self first, ancestor last
• the GoodStudent part of the memory initialized first,

the Student part
Swift Constructor Calls
Designate
Convenience
Swift Constructor Calls
Parent
Child
Private Variables and Inheritance
private variables are still “inherited” in
memory, but not “visible” to the subclass
because of encapsulation (security)
• protected: accessible to Child(subclass)
• public: everyone
• internal (default): same package classes
• protected: sub-classes
• private: class self
Swift Access Permissions
Access Permission (Swift)
• Child: same or more close than Parent
References
• Apple: Access Control and protected
• http://commons.oreilly.com/wiki/images/a/a7/
Beyond_Java_I_2_tt13.png
• https://upload.wikimedia.org/wikipedia/commons/
thumb/4/47/C3_linearization_example.svg/600px-
C3_linearization_example.svg.png
• https://developer.apple.com/library/content/
documentation/Swift/Conceptual/
Swift_Programming_Language/Art/
initializerDelegation02_2x.png
Ad

Recommended

OOP in JS
OOP in JS
Eugene Lazutkin
 
2 Day Android Workshop
2 Day Android Workshop
Daniel M.Idrees
 
Object Oriented Programming in Swift Ch0 - Encapsulation
Object Oriented Programming in Swift Ch0 - Encapsulation
Chihyang Li
 
IFI7184.DT lesson1- Programming languages
IFI7184.DT lesson1- Programming languages
Sónia
 
RIBBUN SOFTWARE
RIBBUN SOFTWARE
mosewoodward24
 
Introduction what is java
Introduction what is java
sanjeeviniindia1186
 
Object Oriented Programming Ch3 SRP, DIP, ISP
Object Oriented Programming Ch3 SRP, DIP, ISP
Chihyang Li
 
Shamaeva fearless sourcing on LinkedIn 19.2.2014
Shamaeva fearless sourcing on LinkedIn 19.2.2014
Irina Shamaeva
 
Research paper
Research paper
hirrahAzhar
 
Unit 3 notes.pdf
Unit 3 notes.pdf
Revathiparamanathan
 
OOP lecture 04
OOP lecture 04
University of Chitral
 
O op lecture 04
O op lecture 04
University of Chitral
 
Java programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- Inheritance
Jyothishmathi Institute of Technology and Science Karimnagar
 
Inheritance and Substitution
Inheritance and Substitution
adil raja
 
Inheritance in Object-Oriented Programming (OOP) (not).pptx
Inheritance in Object-Oriented Programming (OOP) (not).pptx
MattFlordeliza1
 
Inheritance in oops
Inheritance in oops
Hirra Sultan
 
java_vyshali.pdf
java_vyshali.pdf
Vyshali6
 
Overview of Object Oriented Programming using C++
Overview of Object Oriented Programming using C++
jayanthi699330
 
Swift Tutorial Part 2. The complete guide for Swift programming language
Swift Tutorial Part 2. The complete guide for Swift programming language
Hossam Ghareeb
 
Relationship of inheritance in oopm.pptx
Relationship of inheritance in oopm.pptx
ayush626953
 
Object Oriented Programming
Object Oriented Programming
sharmisivarajah
 
lecture 6.pdf
lecture 6.pdf
WaqarRaj1
 
Lecture 3
Lecture 3
talha ijaz
 
presentation on inheritance concept in c++
presentation on inheritance concept in c++
GaurangVishnoi
 
Inheritance in OOPs with java
Inheritance in OOPs with java
AAKANKSHA JAIN
 
Swift vs Objective-C
Swift vs Objective-C
Mindfire Solutions
 
java part 1 computer science.pptx
java part 1 computer science.pptx
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
Object Oriented Programming Concepts
Object Oriented Programming Concepts
Abhigyan Singh Yadav
 
Image Style Transfer and AI on iOS Mobile App
Image Style Transfer and AI on iOS Mobile App
Chihyang Li
 
Image style transfer and iOS CoreML, Vision Frameworks
Image style transfer and iOS CoreML, Vision Frameworks
Chihyang Li
 

More Related Content

Similar to Object Oriented Programming in Swift Ch1 - Inheritance (20)

Research paper
Research paper
hirrahAzhar
 
Unit 3 notes.pdf
Unit 3 notes.pdf
Revathiparamanathan
 
OOP lecture 04
OOP lecture 04
University of Chitral
 
O op lecture 04
O op lecture 04
University of Chitral
 
Java programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- Inheritance
Jyothishmathi Institute of Technology and Science Karimnagar
 
Inheritance and Substitution
Inheritance and Substitution
adil raja
 
Inheritance in Object-Oriented Programming (OOP) (not).pptx
Inheritance in Object-Oriented Programming (OOP) (not).pptx
MattFlordeliza1
 
Inheritance in oops
Inheritance in oops
Hirra Sultan
 
java_vyshali.pdf
java_vyshali.pdf
Vyshali6
 
Overview of Object Oriented Programming using C++
Overview of Object Oriented Programming using C++
jayanthi699330
 
Swift Tutorial Part 2. The complete guide for Swift programming language
Swift Tutorial Part 2. The complete guide for Swift programming language
Hossam Ghareeb
 
Relationship of inheritance in oopm.pptx
Relationship of inheritance in oopm.pptx
ayush626953
 
Object Oriented Programming
Object Oriented Programming
sharmisivarajah
 
lecture 6.pdf
lecture 6.pdf
WaqarRaj1
 
Lecture 3
Lecture 3
talha ijaz
 
presentation on inheritance concept in c++
presentation on inheritance concept in c++
GaurangVishnoi
 
Inheritance in OOPs with java
Inheritance in OOPs with java
AAKANKSHA JAIN
 
Swift vs Objective-C
Swift vs Objective-C
Mindfire Solutions
 
java part 1 computer science.pptx
java part 1 computer science.pptx
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
Object Oriented Programming Concepts
Object Oriented Programming Concepts
Abhigyan Singh Yadav
 
Inheritance and Substitution
Inheritance and Substitution
adil raja
 
Inheritance in Object-Oriented Programming (OOP) (not).pptx
Inheritance in Object-Oriented Programming (OOP) (not).pptx
MattFlordeliza1
 
Inheritance in oops
Inheritance in oops
Hirra Sultan
 
java_vyshali.pdf
java_vyshali.pdf
Vyshali6
 
Overview of Object Oriented Programming using C++
Overview of Object Oriented Programming using C++
jayanthi699330
 
Swift Tutorial Part 2. The complete guide for Swift programming language
Swift Tutorial Part 2. The complete guide for Swift programming language
Hossam Ghareeb
 
Relationship of inheritance in oopm.pptx
Relationship of inheritance in oopm.pptx
ayush626953
 
Object Oriented Programming
Object Oriented Programming
sharmisivarajah
 
lecture 6.pdf
lecture 6.pdf
WaqarRaj1
 
presentation on inheritance concept in c++
presentation on inheritance concept in c++
GaurangVishnoi
 
Inheritance in OOPs with java
Inheritance in OOPs with java
AAKANKSHA JAIN
 
Object Oriented Programming Concepts
Object Oriented Programming Concepts
Abhigyan Singh Yadav
 

More from Chihyang Li (20)

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

Recently uploaded (20)

Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Varsha Nayak
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Technologies
 
Download Adobe Illustrator Crack free for Windows 2025?
Download Adobe Illustrator Crack free for Windows 2025?
grete1122g
 
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
soulamaabdoulaye128
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
What is data visualization and how data visualization tool can help.pptx
What is data visualization and how data visualization tool can help.pptx
Varsha Nayak
 
SAP Datasphere Catalog L2 (2024-02-07).pptx
SAP Datasphere Catalog L2 (2024-02-07).pptx
HimanshuSachdeva46
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Intelli grow
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
BradBedford3
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Varsha Nayak
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Technologies
 
Download Adobe Illustrator Crack free for Windows 2025?
Download Adobe Illustrator Crack free for Windows 2025?
grete1122g
 
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
soulamaabdoulaye128
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
What is data visualization and how data visualization tool can help.pptx
What is data visualization and how data visualization tool can help.pptx
Varsha Nayak
 
SAP Datasphere Catalog L2 (2024-02-07).pptx
SAP Datasphere Catalog L2 (2024-02-07).pptx
HimanshuSachdeva46
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Intelli grow
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
BradBedford3
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
Ad

Object Oriented Programming in Swift Ch1 - Inheritance