Java Magazine, Sept/Oct 2018
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2018 68 design patterns public class TextNodeOld extends Node private StringBuilder text new StringBuilder public TextNodeOld empty public TextNodeOld String s Here you know the StringBuilder exists and is empty text append s public String getText return text toString public void setText String text this text setLength 0 this text append text Lots of supplemental functionality methods here that will be added below Its becoming annoying that all the data types need to be modified every time somebody has an idea for a new function I know from experience that Im unlikely to be able to predict at the start of the maintenance all the remaining functionality that will be needed So Ill introduce a Visitor pattern The basic data structure is still the Node with subclasses TextNode and ImageNode A real word processor would have more types of nodes but I want to focus on the Visitor pattern not com
You must have JavaScript enabled to view digital editions.