Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

Design Patterns ใน JavaScript มีอะไรบ้าง?

Design patterns แทน best practices ที่นักพัฒนาอาวุโสใช้ Design patterns เป็น solutions สำหรับปัญหาทั่วไปที่เจอระหว่างพัฒนา software ได้มาจาก trial and error ของนักพัฒนาหลายคนหลายปี

Design patterns เป็น language agnostic แบ่งได้ 3 หมวด: Creational, Structural, Behavioral

Creational Patterns - ให้วิธีสร้าง objects พร้อมซ่อน creation logic แทนที่จะ instantiate ด้วย new operator โดยตรง ให้ flexibility ในการตัดสินใจว่าสร้าง objects ไหนสำหรับ use case ใด ตัวอย่าง: Factory, Builder, Singleton

Structural Patterns - เกี่ยวกับ class และ object composition ใช้ inheritance compose interfaces และกำหนดวิธี compose objects เพื่อ functionality ใหม่ ตัวอย่าง: Adapter, Decorator, Facade

Behavioral Patterns - เกี่ยวกับ communication ระหว่าง objects ตัวอย่าง: Observer, Iterator, Strategy