Software Design and Development Winter 1997 COM 1205 --------------------------------------------------------------------------- Assignment 1 Due date: Monday, Jan. 13 --------------------------------------------------------------------------- This assignment is stored in file $SD/hw/1 in file assign.txt THEME: Reverse Engineering of Java programs ========= On CCS Northeastern machines, OO=/proj/adaptive/www/course/ AOO=/proj/adaptive/www/course/f96/ On the WWW, OO = http://www.ccs.neu.edu/research/demeter/course/ On the WWW, AOO = http://www.ccs.neu.edu/research/demeter/course/f96 The course directory is: SD=$OO/w97-ug/ Further useful URLs are on page 589 of the AP book. ========= 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 ccs.courses.com1205@ccs.neu.edu johan@ccs.neu.edu Get the class packet from Gnomon Copy, 325 Huntington Avenue WHEN ITS READINESS IS ANNOUNCED IN CLASS. Get the text book from the bookstore. Get an account on Northeastern machines if you don't have one already. Set it up to use C++ and Java compilers and the Demeter Tools/C++. IMPORTANT: The first non-comment line in your .software file has to be: GNU # Make GNU utils override standard system commands The reason is that we will use make files in the course and the GNU make file notation is better than the normal UNIX make file notation. 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 read the equivalent in your favorite Java book. Skim read: $AOO/APbookWithDemJava.html $AOO/demjava/FromDemC++ToDemJava.html http://www.ccs.neu.edu/home/lieber/ap-projects.html 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 with suffix *.java make up the program. Put the Java virtual machine into your path by using: set path = ( $path /proj/demsys/demjava/bin ) Don't forget to "source" your shell initialization file. You can run the program by typing java Main < tree.input which will read the object described in file tree.input, create a Java object and process it. Focus your reengineering effort on 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/ot/uml.html Use /arch/com/bin/acroread to read the Acrobat files after downloading. Much of this information is also in your class packet. ) List the directed associations in this class diagram. For each association, give source class, label (name of role) and target class. 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 vocabolary. Turn in the list of directed associations in the form shown above. 2. What are the classes defined by the UML class diagram and implemented in the Java program? Turn in the list of class names and a description of their interfaces. An interface of a class is a list of the types of the methods which the class provides. Java supports the concept of an interface. Use Java syntax to describe the interfaces. An example of a Java interface is: interface Attributed { void add(At newAt); Attr find(String attrName); java.util.Enumeration attrs(); } Such an interface may be used to define a class: class a implements Attributed {...} 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 traverse methods only (with name *_traverse). Here is a start: When java Main < tree.input 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 parser generator whose functioning will not be explained here; see http://www.suntest.com/Jack/ for more information. Rarely we also use an alternative parser generator in /proj/demsys/demjava/java_cup. But this one will be phased out since it is not supported. The Jack parser generator is supported by SUN and is expected to become a popular Java tool which you might soon encounter in your COOP work. See http://www.javaworld.com/javaworld/jw-12-1996/jw-12-jack.html for a magazine article on Jack. You don't have to learn the details of Jack since Demeter/Java creates all the Jack files for you.) In the following we only explain the behavior of the methods with name *_traverse. This is all which is required. 4. Use the Java constructor notation to construct (the first 5 constructor calls only) 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 $SD/hw/1/graph The relevant program is in file class-graph.java. "tree" should be properly replaced by "class-graph". Turn in the same information as for part A. In addition, answer the following by turning in the modified program. How would you modify the program so that it counts the number of inheritance relationships in the input graph? For example, A : B | C. B : X | Y. C =. X =. Y =. contains 4 inheritance relationships. 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: ===================================================================== This part is for the entire class. Find out where the Java compiler lives on your system. On the NU CCS network it is at /arch/unix/bin/guavac and a better compiler from Netscape: /proj/demsys/demjava/bin/javac (So make sure /arch/unix/bin and /proj/demsys/demjava/bin are in your path.) You might need compiled Java classes from a library. Therefore, make sure that the environment variable CLASSPATH is set properly: setenv CLASSPATH .:/proj/demsys/demjava/classes:/share/unix/packages/guavac/lib After this preparation, try the Java compiler using: javac -d . tree.java Parser.java ParserConstants.java ParserTokenManager.java ASCII_CharStream.java or guavac -d . tree.java Parser.java ParserConstants.java ParserTokenManager.java ASCII_CharStream.java Turn in the output produced by the compiler. If you put /proj/demsys/demjava/bin into your path (for example, by using: set path = ( $path /proj/demsys/demjava/bin ) you can also recompile everything and run by using make clean ls make test (using the Makefile which is in the directory). IMPORTANT: The makefiles need gnu make (/arch/gnu/bin/make); they'll break with the normal make. E-mail submission ================= Please follow the following rules: WHERE Send your solution to the teaching assistant (email: com1205-grader@ccs.neu.edu). He/she stores the solutions and I can inspect them electronically. ONE ASCII FILE Send only ONE ascii file containing your hw 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 Java programs used in this homework have been generated by the C++ program, called Demeter/Java, in /proj/demsys/demjava/sourceC++/Java That C++ program itself has been generated by the Demeter Tools/C++. /proj/demsys/demjava/sourceC++/Java is about a 20 000 line C++ program which was written by Doug Orleans in a few weeks. Adaptiveness of the behavior shortened the most challenging part of the program by a factor of 6! Demeter/Java is currently under development and not (yet) intended for your use. However, if you are curious, the instructions are at URL: $AOO/demjava/usingDemJava.html =================== The directory containing administrative information and homeworks is: $SD/ IMPORTANT: YOUR directory for this course is a subdirectory of /proj/demsys/com1205/w97 Use your NU CCS login name as directory name! For example, if your NU CCS login is xyz, create a directory W = /proj/demsys/com1205/w97/xyz Put your homework solutions into a subdirectory of $W/hw and your project work into a subdirectory of $W/project You have about 20 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. 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. 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. just a class: it is a data structure together with operations on that data structure. It is called abstract since the implementation is hidden. Has nothing to do with an abstract data type. 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? You don't have to turn in any UML class diagrams but you are encouraged to draw them anyway.