- ProgrammingLanguageClass/2006/Report2
= PostScript =
- SmalltalkBestPracticePatterns/DispatchedInterpretation
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.
Found 2 matching pages out of 7540 total pages
You can also click here to search title.