Trung BìnhDesign Patterns iconDesign Patterns

Khi nào nên dùng Structural patterns? Cách chọn đúng?

Structural patterns giải quyết cách compose class và object thành larger structures. Chọn theo use case:

  • Adapter: tích hợp incompatible interface (thường là third-party lib)
  • Bridge: thiết kế mới cần tách abstraction-implementation để scale độc lập
  • Composite: dữ liệu có dạng tree, cần treat leaf/branch đồng nhất
  • Decorator: thêm behavior tại runtime mà không sửa class gốc
  • Facade: đơn giản hóa subsystem phức tạp cho client
  • Proxy: control access hoặc add cross-cutting concern (logging, caching, auth)
  • Flyweight: memory optimization critical với nhiều objects tương đồng

Nhiều pattern Structural có thể kết hợp — Facade có thể dùng bên trong các Proxy; Decorator và Composite hay đi cùng nhau trong UI tree.

Xem toàn bộ Design Patterns cùng filter theo level & chủ đề con.

Mở danh sách Design Patterns