Template Method pattern กำหนด โครงร่าง (skeleton) ของอัลกอริทึม ไว้ใน base class โดยให้ subclasses เติมขั้นตอนเฉพาะโดยไม่เปลี่ยนโครงสร้างโดยรวม มันจับกระบวนการร่วม (common process) ในขณะที่อนุญาตให้ปรับแต่งแต่ละขั้นตอนได้
Template Method pattern ทำอะไร
TEMPLATE METHOD → define an algorithm's overall STRUCTURE in a base method, with some STEPS
left for subclasses to implement:
→ the base class controls the overall flow (the "template")
→ subclasses override specific STEPS (the parts that vary)
→ the algorithm's structure is FIXED; the steps are customizable
→ "common process, customizable steps"
