Object Oriented Programming in Swift Ch0 - Encapsulation
-
Upload
chihyang-li -
Category
Software
-
view
62 -
download
5
Transcript of Object Oriented Programming in Swift Ch0 - Encapsulation
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 Programmingby Josh Ko
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
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)
• ReuseC language
• NOP: spaghetti code + (possibly spaghetti) dataAssembly
• POP: organized code + (possibly organized) data C, PASCALbasic modules: procedures
Noodles -> Procedure -> Object
• NOP: spaghetti code + (possibly spaghetti) dataAssembly
• POP: organized code + (possibly organized) data C, PASCALbasic modules: procedures
• OOP: organized code + organized data (grouped) Swift, Java, Pythonbasic modules: Class / Struct
Noodles -> Procedure -> Object
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 Programminghow 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 Programminghow 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 Programminghow to implement it• class diagrams -> implementations• OOP, this one
Data Abstraction
Abstraction is selective ignorance. by Andrew Koenig
Others care about the interface and ignore the implementation
Design by Contract• Class Invariant
• Valid State
• 1 <= day <= 310 <= hour <= 24
private(set)private(set)
• 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 ozThink 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
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