Chapter 2: Designing a Document Editor: Case Study

Loading audio…

ⓘ This audio and summary are simplified educational interpretations and are not a substitute for the original text.

If there is an issue with this chapter, please let us know → Contact Us

The first major challenge involves defining the document's internal arrangement, which requires a hierarchical representation that treats simple elements like characters and complex elements like diagrams uniformly. This is solved through recursive composition and the Composite Pattern (163), defining all elements as abstract Glyph objects. Next, formatting text into lines and columns must be flexible to accommodate different algorithms and user constraints; this necessity for interchangeable algorithms is met by encapsulating the formatting logic into Compositor objects, applying the Strategy Pattern (315). Enhancing the user interface with features like scroll bars and borders without relying on inflexible inheritance leads to the use of transparent enclosure, which is formalized by the Decorator Pattern (175), allowing embellishments to wrap components transparently. To support multiple look-and-feel standards (like Motif or Presentation Manager), the design abstracts the process of creating related families of widgets using the Abstract Factory Pattern (87), ensuring that the application doesn't hard-code dependencies on concrete platform classes. Similarly, managing portability across different window systems (e.g., X, PM) is achieved by separating the logical window abstraction (Window) from its platform-specific implementation (WindowImp) using the Bridge Pattern (151). For handling user interactions available via menus and buttons, including the critical feature of arbitrary undo and redo, the design encapsulates requests into polymorphic Command objects (233). Finally, supporting analytical operations such as spelling checking and hyphenation requires two separate patterns: the Iterator Pattern (257) abstracts the mechanisms for accessing and traversing the scattered hierarchical document structure, while the Visitor Pattern (331) encapsulates the analysis itself, allowing new analytical capabilities to be added without modifying the core Glyph class hierarchy.