Hand-ons design pattern
Head first design pattern
- Identify the aspects of your application that vary and separate them from what stays the same.
<Nhận dạng các thành phần hay thay đổi trong ứng dụng và tách biệt chúng ra khỏi phần chung của ứng dụng> - Program to an interface, not an implementation.
<Lập trình interface, không phải là một implementation (bản thực thi) - polymorphism> - Favor composition over inheritance.
<Ưu tiên composition (kết tập) hơn là inheritance (kế thừa)> - Strive for loosely coupled designs between objects that interact.
<Cố gắng thiết kế sự tương tác của các objects là loosely coupled> - Classes should be open for extension, but closed for modification.
<Các classes nên được open để mở rộng (extend), đóng lại (closed) để chỉnh sửa> - Depend upon abstractions. Do not depend upon concrete classes
<Phụ thuộc vào abstraction, không phụ thuộc vào các class rời rạc> - Talk only to your immediate friends <Chỉ kết nối với các class cần thiết>
#Note
-
Open for extension but closed for modification.
-
Guidelines for Dependency Inversion Principle:
- No variable should hold a reference to a concrete class
<If using new, it is holding a reference to a concrete class. Use a factory to get around that. - No class should derive from a concrete class
<If deriving from a concrete class, it is depending on a concrete class. Derive from an abstraction, like an interface or an abstract class. - No method should override an implemented method of any of its base classes
<Sometime, it is impossible>
- No variable should hold a reference to a concrete class