CSC152 2005S, Class 22: Object-oriented design and Interfaces Admin: * Still lecture/discussion style class. Please contribute. * Questions on the exam? Overview: * Review! * Representing operations * Implementing Surround * Using interfaces Review: * Goal: Create fun way to compose (shove together) text * So far: * Class for line or portion of line (TextLine) * Class for group of lines (or portions) (SimpleTextBlock) * Need to think about operations Operations we might apply to blocks of text in the process of building a bigger or nicer looking block of text * Surround with stars * Reformat to meet a different width * Emphasize a single line by surrounding with stars * Translate (take 206 or whatever) * Indent (add spaces to the left) * Truncate (remove stuff from the right) * Combine horizontally * Combine vertically * Dada-ize Where do these operations go? (I.e., in what class) or how do I represent these operations? * Don't represent them as methods, represent them as objects. * E.g., a chunk of text surrounded by stars is in class SurroundedByStars, * Similarly, two chunks of text composed horizontally are in class HorizontalComposition SimpleTextBlock bigF = ...; SimpleTextBlock lincoln = "ourscore and seven years ago"; HorizontalComposition speech = new HorizontalCompositions( bigF, lincoln); Let's consider SurroundedByStars * One constructor SurroundByStars(SimpleTextBlock stb) * What methods should it provide? * Need a way to print it out * Count how many stars are printed * Get the unsurrounded text <-- * Number of lines, width <-- * Get a given line as a string <-- * What fields should it include? * The unsurrounded text Observation: * SurroundedText and SimpleTextBlock provide the same methods * Hence, we should be able to surround the surrounded text with stars, too (with little extra work) In Java, when you have different classes that provide the same methods, you summarize the commonality in an interface