Có ai giải thích hộ e câu này… và cho ví dụ với ạ… “Template methods use inheritance to vary part of an algorithm. Strategies use delegation to vary the entire algorithm.”
đây là 2 mẫu liên quan tới nhau… template method va strategy method…
Design patterm strategy method
http://www.uml.org.cn/c++/pdf/DesignPatterns.pdf
Trang này ạ… Trang số 365 ạ… phần các mẫu liên quan…
1 Like
Lời khuyên của mình là bạn nên đọc cuốn khác. Lúc đầu học design pattern mà vọc luôn GOF cũng chẳng hiểu gì cả. Chuyển sang đọc headfirst design patterns cho de hiểu.
2 Likes
Dạ… e cảm ơn mấy anh nhiều ạ… hì hì…
template methods dùng lớp kế thừa để thay đổi một phần thuật toán, Strategies… khó dịch quá
vào đây xem thử sự khác nhau:
http://stackoverflow.com/questions/669271/what-is-the-difference-between-the-template-method-and-the-strategy-patterns
1 Like