Use Composite pattern to construct book components.
Moudle is totally independent from other object.
Seperate java source file into different package
module
Including all the components: Book, Chapter, Section, Paragraph.
view
Use Observer pattern to communicate between moudle and view.
Concrete Observer: BookViewer
control
BookReader: build the book form xml file
BookTree: display the tree structure, use Observer pattern to notify Viewer
formatter
Defined the formatter for the book component.
Use simple Strategy pattern.
Implementation:
Module
Use Composite Pattern
Create an interface "Component".
Class "BookComponent" is an abstract class which implements iterface "Component".
Book extends BookComponent
Is composite.
Has its own author name.
Has child list.
Chapter, Section extends BookComponent
Is composite.
Has child list.
Paragraph extends BookComponent
Is leaf.
No child list.
Has its own string vector.
View
Observer Pattern
Interface "Subject" is a subject interface.
Interface "Viewer" is an observer interface.
Class "BookSubject" implements interface "Subject", which can publish the book componenet to observer and notify the obsever when user click the BookTree object..
Class "BookViewer" extends JFrame and implemets iterface "Viewer".
Control
BookTree
Create the tree structure from book.
The tree node type is "BookSubject", when ever user click the tree node, it will notify the observer which subscribe it.
BookReader
Parsing the XML file to contruct the book.
Formatter
Strategy Pattern
Use a very very simple strategy pattern to build formatter.
Interface "ComponentFormatter" defined the method to display a book component.
Class "BookFormatter", "ChapterFormatter", "SectionFormatter", "ParagraphFormatter" implements interface "ComponentFormatter" but with different display effect.
Class "BookViewer" use different formatter while displaying the book content.
No comments:
Post a Comment