正在加载图片...
$21.2 FINDING THE ABSTRACTIONS 699 21.2 FINDING THE ABSTRACTIONS The key step in an object-oriented solution is the search for the right abstraction.Here the fundamental notion is staring us in the eyes. Command as a class The problem is characterized by a fundamental data abstraction:COMMAND, representing any editor operation other than Undo and Redo.Execution is only one of the features that may be applied to a command:the command might be stored,tested-or undone.So we need a class of the provisional form deferred class COMMAND feature execute is deferred end undo is deferred end end COMMAND describes the abstract notion of command and so must remain deferred. Actual command types are represented by effective descendants of this class,such as class LINE DELETION inherit COMMAND feature deleted line index:INTEGER deleted line:STRING set deleted line index (n:INTEGER)is -Set to n the number of next line to be deleted. do deleted line index:=n end execute is --Delete line. do "Delete line number deleted line index" "Record text of deleted line in deleted line" end undo is --Restore last deleted line. do "Put back deleted line at position deleted line index" end end And similarly for each command class.§21.2 FINDING THE ABSTRACTIONS 699 21.2 FINDING THE ABSTRACTIONS The key step in an object-oriented solution is the search for the right abstraction. Here the fundamental notion is staring us in the eyes. Command as a class The problem is characterized by a fundamental data abstraction: COMMAND, representing any editor operation other than Undo and Redo. Execution is only one of the features that may be applied to a command: the command might be stored, tested — or undone. So we need a class of the provisional form deferred class COMMAND feature execute is deferred end undo is deferred end end COMMAND describes the abstract notion of command and so must remain deferred. Actual command types are represented by effective descendants of this class, such as class LINE_DELETION inherit COMMAND feature deleted_line_index: INTEGER deleted_line: STRING set_deleted_line_index (n: INTEGER) is -- Set to n the number of next line to be deleted. do deleted_line_index := n end execute is -- Delete line. do “Delete line number deleted_line_index” “Record text of deleted line in deleted_line” end undo is -- Restore last deleted line. do “Put back deleted_line at position deleted_line_index” end end And similarly for each command class
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有