- SmalltalkBestPracticePatterns/DispatchedInterpretation . . . . 7 matches
For example, consider a graphical Shape represented by a sequence of line, curve, stroke, and fill commands. Regardless of how the Shape is represented internally, it can provide a message #commandAt: anInteger that returns a Symbol representing the command and #argumentsAt: anInteger that returns an array of arguments. We could use these messages to write a PostScriptShapePrinter that would convert a Shape to PostScript:
PostScriptShapePrinter>>display: aShape
This is a simplified case of Dispatched Interpretation because there is only a single message coming back. For the most part, there will be several messages. For example, we can use this pattern with the Shape example. Rather than have a case statement for every command, we have a method in PostScriptShapePrinter for every command, For example:
PostScriptShapePrinter>>lineFrom: fromPoint to: toPoint
PostScriptShapePrinter>>display:aShape
PostScriptShapePrinter>>display: aShape
The name "dispatched interpretation" comes from the distribution of responsibility. The encoded object "dispatches" a message to the client. The client "interprets" the message. Thus, the Shape dispatches message like #lineFrom:to: and #curveFrom:mid:to:. It's up to the clients to interpret the messages, with the PostScriptShapePrinter creating PostScript and the ShapeDisplayer displaying on the screen.
- DispatchedInterpretation . . . . 6 matches
class PostScriptShapePrinter
모든 커맨드를 위한 case 구문을 쓰지 말고, PostScriptShapePrinter에 모든 커맨드를 두자.
void PostScriptShapePrinter::line(Point& from, Point& to)
void PostScriptShapePrinter::curve(/* ... */) { /* ... */ }
void PostScriptShapePrinter::display(Shape& aShape)
void PostScriptShapePrinter::display(Shape& aShape)
Found 2 matching pages out of 7555 total pages (5000 pages are searched)
You can also click here to search title.