Pattern-Oriented Software Design (Fall 2009) Homework#1 (Due 2009/10/06) 1 Introduction In this course, you are required to develop a software application – MyMind. MyMind is a mind mapping tool which helps users organize and visualize their thoughts using a tree-like structure. For example, Fig 1 shows a mind map of computer knowledge. Things related to the topic are derived (by the user) and drawn as subtrees linked to the root. Moreover, a subtopic can also be used to derive other subjects. The example is drawn by using FreeMind, which can be downloaded from http://freemind.sourceforge.net. Fig 1: A mind map example of the computer knowledge topic The development of MyMind is divided into several iterations. Each iteration has a number of requirements to be implemented. In general, the requirements include implementing a number of system features, applying one or two design patterns in your design, writing and performing unit testing in your program, and drawing class diagrams for your design. Note that MyMind is not the same as FreeMind – some changes will be made to make them different. 1 In this homework, the first iteration of the development, you are required to implement an initial data structure and a text-mode interface for MyMind. The design of the data structure must apply Composite pattern. The text-mode interface offers a menu for the user to create a new mind map, insert nodes into the map, and save the map as a text file. 2 Requirements 2.1 Applying Composite Pattern The core data structure of a mind map is a composite structure (see Fig 2). Note that the structure is a variant of composite pattern – it has no leaf elements. In the class diagram, AbtstractNode is an abstract class defining a set of operations; it is the component element in the composite pattern. The class CompositeNode is a subclass of AbstractNode and it maintains a list storing some other child nodes. The two operations, addParent and addSibiling, are unimplemented. It is the composite element. The classes RootNode and Node are two specialized nodes of ComposisteNode. The difference of them is that RootNode does not have any parent and sibling nodes. Since both RootNode and Node inherit ComposisteNode, they are also composite elements. Fig 2: The composite structure in MyMind 2 In this homework, you are required to apply the composite pattern to implement the data structure in your program. The class diagram shown in Fig.2 is an initial, rough design; your design will be more sophisticated. 2.2 A Text-mode Interface The first implementation of MyMind does not need a GUI interface. Instead, a text-mode interface for the user to interact with the application is required. Fig 3 shows an example interface. The “>” is a “prompt” symbol used to prompt the user to enter a choice using a keyboard. Please enter your choice: 1. Create a new mind map 2. Insert a new node 3. Display mind map 4. Save mind map 5. Exit > Fig 3: The text-mode interface of MyMind The text-mode interface provides the following options. First, the user can create a new mind map. A new mind map should ask the user to input a topic, and the topic becomes the root node of the new mind map. Second, after a new map is created, the user can insert a number of nodes into the mind map. To insert a new node, three input data are required – <nid> <new_nid> <desc>. The nid specifies a parent, a child, or a sibling node. The new_nid and desc are used to create the new node. Note that the id of a node is unique. There are three types of insertions – inserting a child node, a parent node, and a sibling node. Please use an implementation that uses a sub-menu to choose the type of insertion. Fig 4 shows an interaction example, where a sub-menu is displayed after the user chooses to insert a new node. 4. Save mind map 5. Exit > 2 a. Insert a parent node b. Insert a child node c. Insert a sibling node > Fig 4: A further menu for inserting a new node 3 For example, if a user wants to insert a new node A2 as a child of node A in the mind map shown in Fig 5. There are two ways to accomplish this job – inserting the new node as a sibling node of A1 or as a child node of A. On the other hand, if the user inserts a parent node of node B, the new parent node will be a child node of node T and the parent of node B. A1 A T A2 B Fig 5: An example mind map which a new node A2 would be inserted into The third function of the text-mode interface is to display the entire mind map. The display is a simple listing of all nodes. Note that appropriate indentations (tabs and spaces) are required (see the example shown in Fig 6.) The type (RootNode and Node), id, and description of a node should be displayed. 4. Save mind map 5. Exit > 4 The mind map T is displayed as follows: T (RootNode, ID: 0) A (Node, ID: 10) A1 (Node, ID: 110) A2 (Node, ID: 111) B (Node, ID: 20) Fig 6: An example of displaying the mind map of Fig 5 The fourth function is to save the mind map as a text file. The detailed format of the file will be described in Section 2.3. You do not need to implement the function of reading a previously saved text file. The fifth function is to exit MyMind. Please notify the user to save the mind map before the exit. 2.3 File Format of Mind Map The output file format of a mind map is a simple list. Each node of the mind map is stored with an extra tag. In this homework, there are three types of tags (prefixed with //): ROOTNODE and NODE for specifying the information of a root node and a 4 node, respectively. Fig 7 shows an example file that stores the mind map of Fig 5. In this case, clearly, each tag is followed by a single line used to record the information of a node. For a root node, only the id and description are stored. For a node, the id of the parent, and the id and description of the stored element are stored. For example, the line 4 of Fig 7 (i.e., 0 10 A) denotes that there is a node whose id and description are 10 and A, respectively, and the node is a child of a node whose id is 0 (i.e., the T node). //ROOTNODE 0 T //NODE 0 10 A //NODE 10 110 A1 //NODE 10 111 A2 //NODE 0 20 B Fig 7: An example of the output file of Fig 5 3 Class Diagram Please draw a UML class diagram to present the design of your program. Several CASE tools are available for you to draw the class diagram, e.g., Dia (http://projects.gnome.org/dia/), StarUML (http://staruml.sourceforge.net), and Microsoft Visio. Note that you should submit the class diagram in JPEG, PNG, or PDF format. 4 Development Environments In this course, there are two development environments you can choose for the implementation. 1. Visual C++ 2008 and MFC 2. Eclipse CDT and QT library For this environment, you can refer the setup document downloadable from http://www.cc.ntut.edu.tw/~yccheng/oop2008/oop.html. Note that you must use C++ language to implementation homework assignments; other languages are not acceptable. If you want to use any other IDEs or libraries, you should visit TA ([email protected];科技大樓 5 1421) for a discussion. Otherwise, your homework will not be graded, if your program cannot be successfully complied. 5 Grading Your homework will be graded as follows: 1. Applying Composite pattern in the design of the mind map (30%) 2. A text-mode interface i. Create a new mind map (5%) ii. Insert a new node (15%) iii. Display mind map (10%) iv. Save mind map (25%) v. Exit (5%) 3. Draw a class diagram (10%) 4. Time Measurement (0%, but necessary) You are required to record your working time into a time log sheet (reference Table 1). The following work items should be noticed: i. Reading the requirement of the homework ii. The design of your implementation, including drawing UML diagrams iii. Coding iv. Testing v. Other work items that spend you a lot of time, e.g., reading GoF book. You must submit your time log; otherwise, your homework will not be graded. Table 1: Time Log Sheet Homework#1, student: ID Date Start Stop … … … Interrupt Hours … Comments … Total Hours: 6 Homework Submission Please login the Open Cyber Classroom (http://mslin.ee.ntut.edu.tw) and submit your homework. Both the login account and password are your student ID. Note that you should change your password after the first login. The submitted files must be a ZIP file named as studentid_hw#.zip, e.g., 94599003_hw1.zip. The ZIP file contains the following items: 6 1. The entire project (visual C++ project or eclipse project) including source code, configuration files, and other related resources. Any complied binary files (e.g., .exe and .o files) should be removed. 2. A class diagram (JPEG/PNG/PDF format) of your program. 3. A time log sheet (see Table 1) (Word document) 4. If any, a text file that describes other issues of your concern. 7
© Copyright 2026 Paperzz