-------------------------------------------------------------------------- Adaptive Object-Oriented Software Development Fall 1997 COM 3360/NTU SE737 --------------------------------------------------------------------------- Assignment 1 Due date: Thursday, Oct. 2 --------------------------------------------------------------------------- This assignment is stored in file $AOO/hw/1 in file assign.txt THEME: Reverse Engineering of Java programs ========= On CCS Northeastern machines, AOO=/proj/adaptive/www/course/f97/ DJ=/proj/adaptive/www/DemeterJava D=/proj/adaptive/www/ On the WWW, AOO = http://www.ccs.neu.edu/research/demeter/course/f97 DJ = http://www.ccs.neu.edu/research/demeter/DemeterJava D = http://www.ccs.neu.edu/research/demeter/ ========= Use the following header for your electronic homework submissions and put it at the top of the message: Course number: COM 3360 / NTU SE737 (whichever applies) Name: Account name: Assignment number: Date: Whenever you have questions about course material, please send e-mail to: mail lieberherr@ccs.neu.edu com3360-grader@ccs.neu.edu ccs.courses.com3360@ccs.neu.edu Get an account on Northeastern machines if you don't have one already and you want one. NTU students get access to the necessary information on the WWW, except the news group ccs.courses.com3360. 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/com3360 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. Read: chapter 4 of UML Distilled by Martin Fowler (called UML book). Skim read: $DJ/forReadersAPBook/APbookWithDemJava.html $DJ/forReadersAPBook/simple-example.txt 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 $AOO/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.) 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 the UML book and: http://www.rational.com/uml/) ) Turn in a picture of the UML class diagram. Use AP Studio http://www.ccs.neu.edu/research/demeter/DemeterJava/use/APStudioUse.html or your favorite drawing tool to create it and turn in the file AP Studio or your drawing tool 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 Tendril, Inc. and they allow you to use their tool for free during the duration of the course. If you want to give it a try, the URL is: www.tendril.com When you ask for the software, indicate that you are a COM 3360 student. ============== 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 their 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 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 The latest version of JavaCC is 0.7pre4 (http://www.suntest.com/JavaCCBeta) Send list administration mail to javacc-interest-request@asap.eng.sun.com Subscribe to javacc-interest-d-request@asap.eng.sun.com for the digest ---------- 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: ================================================================== Similar to part A, but now reverse-engineer the program in $AOO/hw/1/graph The relevant program is in file class-graph.java. "tree" should be properly replaced by "class-graph". 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 are asked to wade through a tremendous amount of Java code: for binary-tree: 3864 lines of Java code generated from 67 lines in tree.beh and tree.cd for graph: 4735 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 produce 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. On my laptop: comp.bat is the file for compilation. RUN.BAT is the file for running the application. On your computing environment you might need to edit those files. File RUN.BAT has produced file out which gives you an idea of what the programs do. ================ PART C: ================================================================== Exercise 1.1 on page 16 of the textbook (Adaptive OO Software). Turn in your reflections about your earlier work. At most 1/2 page. It is fine if you have not experienced those limitations before. ===================================================================== PART D: ===================================================================== Try to compile and run the Java programs in binary-tree and graph on your PC or workstation at work. 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: com3360-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 com3360-grader. He stores the solutions and I can inspect them electronically. If you are in the NTU class, 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. ========== The instructions for downloading Demeter/Java and AP Studio are at: http://www.ccs.neu.edu/research/demeter/DemeterJava/use/DemJavaUse.html http://www.ccs.neu.edu/research/demeter/DemeterJava/use/APStudioUse.html ========== A note for NTU students: for the NTU students we will give out Northeastern (NU) accounts, if you want one. But it is not really needed. You need a Java development environment on your PC or workstation and Internet access, maybe through a phone line. =============== 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/use/DemJavaUse.html $AOO/demjava/usingDemJava.html =================== The directory containing administrative information and homeworks is: $AOO To avoid disk space problems, your working directory for this course should be a subdirectory of /proj/demsys/com3360-f97 Use your NU CCS login name as directory name! For example, if your NU CCS login is xyz, create a directory W = /proj/demsys/com3360-f97/xyz Put your homework solutions into a subdirectory of $W/hw and your project work into a subdirectory of $W/project You have about 10 Megabytes of disk space per student! Use the diskspace responsibly and delete files which are outdated. At the end of the course, you clean up your project directory by deleting any outdated files and then your files will be saved and will be made publically readable for the next class. Please create your subdirectory within 24 hours of getting this. =================== 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. PART B: has two parts: do points 1-4 as in part A, but now for the class graphs AND answer the question: How to modify the program so that it counts the number of subclass relationships in the input graph?