File tree Expand file tree Collapse file tree
composite/src/main/java/com/iluwatar/composite Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3232 * of a composite is to "compose" objects into tree structures to represent part-whole hierarchies.
3333 * Implementing the Composite pattern lets clients treat individual objects and compositions
3434 * uniformly.
35- * <p>
36- * In this example we have sentences composed of words composed of letters. All of the objects can
37- * be treated through the same interface ({@link LetterComposite}).
35+ *
36+ * <p> In this example we have sentences composed of words composed of letters. All of the objects
37+ * can be treated through the same interface ({@link LetterComposite}).
3838 *
3939 */
4040public class App {
4141
4242 private static final Logger LOGGER = LoggerFactory .getLogger (App .class );
4343
4444 /**
45- * Program entry point
45+ * Program entry point.
4646 *
4747 * @param args command line args
4848 */
Original file line number Diff line number Diff line change 2424package com .iluwatar .composite ;
2525
2626/**
27- *
28- * Letter
29- *
27+ * Letter.
3028 */
3129public class Letter extends LetterComposite {
3230
33- private char c ;
31+ private char character ;
3432
3533 public Letter (char c ) {
36- this .c = c ;
34+ this .character = c ;
3735 }
3836
3937 @ Override
4038 protected void printThisBefore () {
41- System .out .print (c );
39+ System .out .print (character );
4240 }
4341}
Original file line number Diff line number Diff line change 2727import java .util .List ;
2828
2929/**
30- *
3130 * Composite interface.
32- *
3331 */
3432public abstract class LetterComposite {
3533
@@ -43,12 +41,14 @@ public int count() {
4341 return children .size ();
4442 }
4543
46- protected void printThisBefore () {}
44+ protected void printThisBefore () {
45+ }
4746
48- protected void printThisAfter () {}
47+ protected void printThisAfter () {
48+ }
4949
5050 /**
51- * Print
51+ * Print.
5252 */
5353 public void print () {
5454 printThisBefore ();
Original file line number Diff line number Diff line change 2626import java .util .List ;
2727
2828/**
29- *
30- * Messenger
31- *
29+ * Messenger.
3230 */
3331public class Messenger {
3432
Original file line number Diff line number Diff line change 2626import java .util .List ;
2727
2828/**
29- *
30- * Sentence
31- *
29+ * Sentence.
3230 */
3331public class Sentence extends LetterComposite {
3432
3533 /**
36- * Constructor
34+ * Constructor.
3735 */
3836 public Sentence (List <Word > words ) {
3937 for (Word w : words ) {
Original file line number Diff line number Diff line change 2626import java .util .List ;
2727
2828/**
29- *
30- * Word
31- *
29+ * Word.
3230 */
3331public class Word extends LetterComposite {
3432
3533 /**
36- * Constructor
34+ * Constructor.
3735 */
3836 public Word (List <Letter > letters ) {
3937 for (Letter l : letters ) {
You can’t perform that action at this time.
0 commit comments