ก่อนหน้า OOP เขียนแบบ Imperative Programing
เกิดปัญหาเวลาทำงานเป็นทีมการแก้ไขจะทำได้ยากในการเขียนแบบ Imperative Programing โค้ดตีกัน
Object-Oriented Programing
OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. — Alan Kay
Classical-OOP
The big idea was to use encapsulated mini-computer in software that communicated via message passing rather than direct data sharing — to stop breaking down programs into separate “ data structure ” and “procedures”
Good code
- ทำงานได้ตามคาดหวัง — Testability
- ทำงานได้รวดเร็ว — Scalability
- อ่านได้ ต่อเติมได้ — Maintainbility
Abstract
เป็นแค่ต้นแบบห้ามเอาไปสร้าง Object
Interface
การบอกว่าสิ่งนี้จะมีหน้าตาแบบนี้
Abstraction & Polymorphism
ไม่ต้องสนใจ entity เอามาพัฒนาต่อได้เลย
The essence of Abstraction & Polymorphism
จะเกิดขึ้นได้มี Factory Pattern แล้วควรใช้ตอนไหนหล่ะ?
วิธีการย้าย conditional statement ไปในจุดที่เราอยากให้มันอยู่
Proof
สามารถพิสูจน์ได้ว่า any if-statement สามารถ re-write with abstraction, Polymorphism and Factory method
Example พัฒนาระบบจัดซื้อ
Business requirement
- only managers can request purchases higher than 10000thb
- User upload a relevant document
- After confirmation, save the document to the storage
Infra requirement
- local environment, save a relevant document to your pc
- In the production environment, upload to our storage
สิ่งที่ทีม Infra สนใจคือ
- encrypt file
- security
- etc.
จุดที่สนใจของแต่ละทีมไม่เหมือนกัน
ถ้าเอา requirement มารวมกันก็จะแย่
- เล่าโค้ดได้ยากขึ้น
- เวลาแก้กระทบเยอะ ไล่โค้ดเยอะ