โดย dawthana » 19/01/2017 2:36 pm
การ Overriding Method (โอเวอร์ไรด เมดธอด) คือถ้าหากต้องการให้
class
(คลาส) ลูกมี
Method (เมธอด) ที่เพิ่มเติมจาก class แม่ โดยให้แทนที่ Medthod ของ class แม่ไปเลยโดยการสร้างชื่อ method ให้เหมือนกับ method ใน class แม่
ตัวอย่างรูปแบบการ Overriding Method การเรียกใช้งาน method ใน class parent (แพเร็นท)
c.Method (ซี.เมธอด) เป็นการเรียก Method ใน c ซึ่ง c ก็คือ
Parent (แพเร็นท) จึง print calling parent Method (ปริ้น คอลลิ่ง แพเร็นท เมดธอด)
- class_parent.png (48.09 KiB) Viewed 1780 times
ตัวอย่างรูปแบบการ Overriding Method การเรียกใช้งาน method ใน class child (คลาส ไชล์ด)
c.Method เป็นการเรียก Method ใน c ซึ่ง c ก็คือ Child จึง print calling child Method เพราะคลาสลูกได้ทำการ overriding Method ของคลาสแม่ไป จึง print calling child Method
- class_child.png (48.05 KiB) Viewed 1780 times
ศึกษาข้อมูลมาจาก
https://www.youtube.com/watch?v=Z3NkS1Z ... lzdKrpxsMM
[b]การ Overriding Method (โอเวอร์ไรด เมดธอด)[/b] คือถ้าหากต้องการให้ [url=https://www.mindphp.com/%E0%B8%84%E0%B8%B9%E0%B9%88%E0%B8%A1%E0%B8%B7%E0%B8%AD/73-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3/2131-class-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3.html]class
(คลาส)[/url] ลูกมี [url=https://www.mindphp.com/%E0%B8%9A%E0%B8%97%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B8%AD%E0%B8%AD%E0%B8%99%E0%B9%84%E0%B8%A5%E0%B8%99%E0%B9%8C/%E0%B8%AA%E0%B8%AD%E0%B8%99-joomla-extension/166-oop-%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87-methods-%E0%B8%AA%E0%B8%B3%E0%B8%AB%E0%B8%A3%E0%B8%B1%E0%B8%9A-class-php5-method-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3.html]Method (เมธอด)[/url] ที่เพิ่มเติมจาก class แม่ โดยให้แทนที่ Medthod ของ class แม่ไปเลยโดยการสร้างชื่อ method ให้เหมือนกับ method ใน class แม่
[b]ตัวอย่างรูปแบบการ Overriding Method การเรียกใช้งาน method ใน class parent (แพเร็นท)[/b]
c.Method (ซี.เมธอด) เป็นการเรียก Method ใน c ซึ่ง c ก็คือ [url=https://www.mindphp.com/%E0%B8%9A%E0%B8%97%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B8%AD%E0%B8%AD%E0%B8%99%E0%B9%84%E0%B8%A5%E0%B8%99%E0%B9%8C/83-python/2907-class-inheritance-.html]Parent (แพเร็นท)[/url] จึง print calling parent Method (ปริ้น คอลลิ่ง แพเร็นท เมดธอด)
[attachment=1]class_parent.png[/attachment]
[b]ตัวอย่างรูปแบบการ Overriding Method การเรียกใช้งาน method ใน class child (คลาส ไชล์ด)[/b]
c.Method เป็นการเรียก Method ใน c ซึ่ง c ก็คือ Child จึง print calling child Method เพราะคลาสลูกได้ทำการ overriding Method ของคลาสแม่ไป จึง print calling child Method
[attachment=0]class_child.png[/attachment]
ศึกษาข้อมูลมาจาก [url]https://www.youtube.com/watch?v=Z3NkS1ZNMng&index=46&list=PLLi1ciqQAf8TVFbJpl7XY23lzdKrpxsMM[/url]