Design pattern Command là gì?
Design pattern Command là gì?
Command đóng gói một yêu cầu thành đối tượng (hành động + tham số), cho phép tham số hoá, xếp hàng, ghi log, hoàn tác (undo) các yêu cầu.
interface Command { void execute(); void undo(); }
class AddText implements Command {
private final Editor editor; private final String text;
AddText(Editor e, String t) { editor = e; text = t; }
public void execute() { editor.append(text); }
public void undo() { editor.removeLast(text.length()); }
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.