2022
Part I: Introducing Object-oriented Programming
1: Procedural Python Examples
2: Modeling Physical Objects with Object-Oriented Programming
3: Mental Models of Objects and the Meaning of “self”
4: Managing Multiple Objects

Part II: Graphical User interfaces with Pygame
5: Introduction to Pygame
6: Object-Oriented Pygame
7: Pygame GUI Widgets

Part III: Encapsulation, Polymorphism, and Inheritance
8: Encapsulation
9: Polymorphism
10: Inheritance
11: Managing Memory Used by Objects

1: Procedural Python Examples


2: Modeling Physical Objects with Object-Oriented Programming


3: Mental Models of Objects and the Meaning of “self”


4: Managing Multiple Objects

5: Introduction to Pygame
6: Object-Oriented Pygame
7: Pygame GUI Widgets

8: Encapsulation
9: Polymorphism

10: Inheritance

p 297 , เป็น mechanism for deriving new class จาก existing class – มากกว่าเริ่มจาก scratch , potentially duplicating code , inheritance เพื่อให้เขียน new class แบบ extend or differentiated
p 298 , Inheritance in OOP
สร้าง class build on(extend) – existing class
และสร้าง class ขึ้นเอง
– include – all method , instance variables
– หรือ add new/different fn
เป็น extremely powerful concept -> ต้อง design class ให้ดี
relationship ระหว่าง 2 classes – base class vs subclass
Base class – class ที่ inherite from , เป็น starting point for subclass
subclass – doing inheriting , enhances base class
Superclass , subclass
Base class , derived class
parent class ,child class


อีกกรณี different , more accurate

p 299 , implementer – base class เป็นเหมือน incorporate เข้าไปใน subclass – ทำให้ base class เป็น part of larger subclass
– เหมือน client of subclass-เป็น single unit- ไม่จำเป็นต้องรู้เกี่ยวกับ base class
p 300 , subclass – สามารถได้ทั้ง extend , following way
– สามารถเป็น redifine method – provide method c same name base class – แต่ different fn – เรียกว่า overriding method
-เมื่อ client ถูก call – overridden method ก็จะถูก call -> code method ใน subclass สามารถเรียก method เหมือน same name in base class
subclass – สามารถ add new method / instance variable – ที่ไม่มีใน base class ได้
subclass c phrase – coding by difference
– เพราะการ Inherit จะ all instance variables , method มาด้วย
– ไม่ต้อง repeat
– only need contain code ที่ differentiated จาก base class
– code ใน subclass – จึง contain new instance variable และ initialization , overriding method ± new method ที่ไม่มีใน base class
Implementing inheritance
syntax ง่าย – base classไม่ต้องรู้ แต่รู้แค่ว่าจะใช้มัน
มีแค่ subclass ที่ต้องการ indicate ว่าตอ้งการ inherit จากbase class
class <BaseClassName>() :
#BaseClass method
class <SubclassName>(<BaseClassName>):
#SubClass methods
p 301 , Employee and Manager Example

11: Managing Memory Used by Objects