-------------------------------------------------------------------------- Software Design and Development Fall 2000 COM 1205 --------------------------------------------------------------------------- Assignment 1 Due date: Wednesday, Sep. 27: PART A and B Wednesday, Oct. 4: PART C and D --------------------------------------------------------------------------- This assignment is stored in file $SD/hw/1 in file assign.txt THEME: Reverse Engineering of Java programs Learn basics of XML by studying Demeter example: Data type definitions (DTDs), documents and Java code generation from XML DTDs. ========= On CCS Northeastern machines, SD=/home/lieber/.www/com1205/f00 DemJ=/proj/adaptive/www/DemeterJava DJ=/proj/adaptive/www/DJ D=/proj/adaptive/www/ On the WWW, SD = http://www.ccs.neu.edu/home/lieber/com1205/f00 DemJ = http://www.ccs.neu.edu/research/demeter/DemeterJava DJ = http://www.ccs.neu.edu/research/demeter/DJ D = http://www.ccs.neu.edu/research/demeter/ To comply with college structures, we also maintain: /course/com1205/f00 = SD and /course/com1205/.www = http://www.ccs.neu.edu/course/com1205 = http://www.ccs.neu.edu/home/lieber/com1205.html ========= Use the following header for your electronic homework submissions and put it at the top of the message: Course number: COM 1205 Name: Account name: Assignment number: Date: Whenever you have questions about course material, please send e-mail to: mail lieberherr@ccs.neu.edu com1205-grader@ccs.neu.edu ccs.courses.com1205@ccs.neu.edu Get an account on Northeastern machines if you don't have one already and you want one. You can get access to the necessary information on the WWW, except the news group ccs.courses.com1205. To listen to that group you need an NU account. For all other work you can use any machine of your choice which runs the latest version of Java. All messages which I send to the class are archived in /proj/demsys/logs-lieber/com1205 If you get your e-mail account late, you can read that file to get up-to-date. READING: Read chapters 1, 3 and 4 of the AP book. Read: chapter 1: A Quick Tour of Java in the Java book by Arnold/Gosling or the approximately equivalent information in your favorite Java book. Skim read the following: $DemJ/forReadersAPBook/APbookWithDemJava.html $DemJ/forReadersAPBook/simple-example.txt About UML class diagrams at www.rational.com/uml About XML: http://www.xml.com/axml/axml.html (XML = eXtensible Markup Language is a W3C Recommendation, i.e., it is a standard.) Read about the Law of Demeter: You can play with yourself. You can play with your own toys (but you can't take them apart), You can play with toys that were given to you. And you can play with toys you've made yourself. For more information: http://c2.com/cgi/wiki?LawOfDemeter http://www.ccs.neu.edu/home/lieber/ap-projects.html (Note: you can propose your own projects, if you want. See the first two entries.) PART A: ================================================================== This homework is about reengineering of Java programs into an object-oriented design. Consider the Java program in directory $SD/hw/1/binary-tree The files in directory gen with suffix *.java make up the program. (Note: The files in gen have been generated by Demeter/Java from the files tree.cd and tree.beh. While you study the Java programs, you also learn how Demeter/Java generates code. The file tree.cd is very similar to an XML schema or an XML document type definition (DTD). The code generation process is similar to the code generation process described in JSR 31 by SUN. This Demeter-like code generation capability is planned to be put into the Java 2 Platform http://www.ccs.neu.edu/research/demeter/technology-transfer/XML/index2.html. The file tree.input that will be used later to create a Java object is similar to an XML document. So we have the following correspondences: XML Demeter Document type definition or schema tree.cd (class dictionary) XML document tree.input (sentence) Java program processing XML document tree.beh (behavior file) The following file gives you information on the code generation process: http://www.ccs.neu.edu/research/demeter/DemeterJava/quick-help/TABLE-OF-CONTENTS.txt ) Start your reengineering effort with file Tree.java. Most of the organization of this file is described in file tree.cd. Answer the following questions: 1. Consider the UML class diagram underlying the Java program. (For information on UML, see http://www.rational.com/uml/ ) Turn in a picture of the UML class diagram. Use your favorite drawing tool to create it and turn in the file that your drawing tool (maybe a pen) produces. Your UML class diagram will contain directed associations. A directed association looks like: -------- -------- | A | 1 | B | | | ----------------->| | -------- x -------- A is the source class, B the target class and x is the name of the role. In the Java implementation, A and B are classes and A has an instance variable x of class B. Association is a synonym for relation. The directed association above presents a binary relation. You think of it as a set of pairs, namely (A-object,B-object) pairs. A natural way to implement such a relation is to store the B-object which is associated with a given A-object in the instance variable x of the A-object. The name "association" comes from the OMT method. It has found its way into the UML vocabulary. Do not put methods and their signatures into your UML class diagram. ============== Why work hard when the computer can do it for you? There is a commercial tool available, called StructureBuilder, which can analyze your Java classes and create the UML class diagram automatically for you. The company is called WebGain http://www.webgain.com/Products/Structure_Builder/index.htm They allow you to use their tool for free during the duration of the course. If you want to give it a try, download the Enterprise edition and use it with: Key = 175044457 Name = NEU Educational User This may only be used by Northeastern students for educational purposes. The code works for the duration of the course (until Dec. 31, 2000). The Enterprise edition is the most powerful of the three available editions and has good support for Enterprise Java Beans. ============== 2. What are the classes defined by the UML class diagram and implemented in the Java program? Turn in the list of classes and a description of their interfaces. Use the Java notation for interfaces. If there is a lot of repetition in your answer, describe in English how the interfaces are structured, instead of spelling them out in detail. 3. Describe the behavior of the program in English. Try to summarize the program as much as possible. Do not just translate the program into English especially when you explain the methods in the Java program. Focus on explaining the methods sum_labels() print_leftTrees() print_allTrees() and the methods they call. Here is a start: When cd gen cd classes java Main < ../../tree.input cd ../.. runs, the Java virtual machine executes the byte code in file Main.class. This code will execute function Main.main which creates a tree object from file tree.input in variable tree using a table-driven parser whose functioning will not be explained here; the parser is automatically generated by a parser generator from SUN: ---------- The JavaCC home page is at http://www.suntest.com/JavaCC ---------- In the following we only explain the behavior of sum_labels(). The behavior is implemented through a traversal which visits all Label-objects and a SummingVisitor ... The output produced by the program is in file out. 4. Use the Java constructor notation to construct the Java object which is created by the Java program when java Main < ../../tree.input is run. This requires a basic understanding of the grammar which is in file tree.cd. If you cannot figure out the object, simply skip this part. The answer starts with new Tree( ... ). PART B: ================================================================== Has two subparts: B.1: do points 1-4 as in part A, but now now reverse-engineer the program in $SD/hw/1/graph AND B.2: answer the question: How to modify the program so that it counts the number of subclass relationships in the input graph? As before, the files in directory gen with suffix *.java make up the program. "tree" should be properly replaced by "class-graph". For B.2: Explain the countInhRels() method. How would you modify the program so that it counts the number of inheritance relationships in the input graph? A : B | C. B : X | Y. C =. X =. Y =. contains 4 inheritance relationships. ================ NOTE ABOUT PARTS A AND B: You can answer the questions by studying the files mentioned below. In addition, you may want to study the generated Java code although it might be confusing. Also keep in mind that there are several ways to generate the code and you see here only one way. You are asked to wade through a tremendous amount of Java code: for binary-tree: a few thousand lines of Java code generated from 67 lines in tree.beh and tree.cd for graph: a few thousand lines of Java code generated out of 54 lines in class-graph.beh and class-graph.cd When you study the Java code keep in mind that it must be very regular since it is produced from a small amount of information. Also keep in mind that not all generated code is actually used by the simple application programs. You have to focus only on the code which is used. ================ PART C: ================================================================== Take a look at: http://www.ccs.neu.edu/research/demeter/DJ/ and get a basic understanding of the package. How would DJ help in solving http://www.ccs.neu.edu/home/lieber/com3336/f99/hw/1/project1-mine.html PART 2 only. For which aspect of PART 2 would it be useful? No programming please. ===================================================================== PART D: ===================================================================== Try to compile and run the Java programs in binary-tree and graph on your PC or workstation at work. Please put the rt.jar file into your class path. See: http://www.ccs.neu.edu/research/demeter/DJ/docs/install.html If you use the CCS .software file, use: CLASSPATH=.:/proj/demsys/demjava/rt.jar Turn in the output produced by the compiler and the output produced by running the program. E-mail submission ================= Please follow the following rules: WHERE Send your solution to the teaching assistant: com1205-grader@ccs.neu.edu using the command submit3360 which is in /proj/demsys/demjava/bin/ Call the submission command in the directory where all your homework answers are in a logically organized directory structure. The submission command automatically collects all the files (including files in subdirectories) and sends them to com1205-grader. He stores the solutions and I can inspect them electronically. If you have good reasons, use your favorite "collection" program to submit the homework but make sure that the grader can unpack on the UNIX platform (for example, using tar). ONE SUBMISSION ONLY PER HOMEWORK Please submit only once when you are done or on the due date, submit a partial solution. COMPLETE SOLUTION Send the complete text of your homework solution. Don't just send a message "my solution is in directory ...". This keeps your solution protected from access by others and allows for faster grading. Submit parts (A and B) / (C and D) separately. ========== The instructions for downloading Demeter/Java and AP Studio are at: http://www.ccs.neu.edu/research/demeter/DemeterJava/setup.html You will find there a nice tool to draw UML class diagrams. ========== If you want to do your homework on your own computer, you need a Java development environment on your PC or workstation and Internet access. =============== The Java programs used in this homework have been generated by Demeter/Java. =============== Demeter/Java is not needed for this homework, but if you are curious, the instructions are at URL: http://www.ccs.neu.edu/research/demeter/DemeterJava/ =================== The directory containing administrative information and homeworks is: $SD =================== Clarifications: An abstract data type is the same as a Java class together with the public method interface and the formal properties of the methods in the public interface. An abstract data type is called _abstract_ since it does not reveal implementation details. An abstract data type is different from an abstract class in Java. In Java, abstract means that you cannot create instances. Abstract data types were invented back in 1974 by Liskov and Zilles. The definition was: It is a data structure together with operations on that data structure and the properties of the operations. The implementation is hidden. In the Java programs you see in the homoework 1, we actually don't use Java interfaces explicitly but we could easily define the interface of each class in Java notation. One reason we don't do this is that we don't want to introduce too many concepts at once and another reason is that often it is sufficient to just work with classes, using the equation class=type. For some applications, however, it is useful to treat classes and interfaces separate. For example, we could define a Java interface interface TreeInterface {...} and then implement class Tree as: class Tree implements TreeInterface { ... } This has the advantage that the TreeInterface could remain stable while we could use different implementations. Reverse engineering means to figure out the design from the program text.