Software Design and = Development Homework 1

Winter 2002 COM 1205

(you can = download the = text version = (http://www.ccs.neu.edu/home/lieber/com1205/w02/hw/1/assign.html) here by right clicking)

 

 

 



Whenever you have questions about course material, = please send e-mail to:

mailto://lieberherr@ccs.neu.edu<= /a>
mailto://com1205-grader@ccs.= neu.edu
 

Teaching assistant: = John Sung (mailto:jser@ccs.neu.edu) =

Direct all homework = questions to com1205-grader@ccs.neu.edu. Only personal correspondence regarding = your grade or appointments should be sent directly to the = TA.



Due date:

This assignment is stored in file $SD/hw/1 in file assign.html
SD=3D/home/lieber/.www/com1205/w02


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=3D/home/lieber/.www/com1205/w02
DemJ=3D/proj/adaptive/www/DemeterJava
DJ=3D/proj/adaptive/www/DJ
D=3D/proj/adaptive/www/
 

On the WWW,
SD =3D http://www.ccs.ne= u.edu/home/lieber/com1205/w02
DemJ =3D http://www.c= cs.neu.edu/research/demeter/DemeterJava
DJ =3D http://www.ccs.neu.ed= u/research/demeter/DJ
D =3D http://www.ccs.neu.edu/r= esearch/demeter
 

To comply with college structures, we also maintain:
/course/com1205/w02 =3D SD and
/course/com1205/.www =3D http://www.ccs.neu.edu/cou= rse/com1205 =3D http://www.ccs.n= eu.edu/home/lieber/com1205.html

The directory = containing administrative information and homeworks is: $SD



Use the following header for your homework = submissions and put it at the top:

Course number: COM = 1205
Name:
Account name:
Assignment number:
Date:

Do NOT include your = student id number in any work you submit because some of your work may be put on = the web.


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/APbookWithDJ.html
$DemJ/forReadersAPBook/APbookWithDemJava.html=
$DemJ/forReadersAPBook/simple-example.txt
 

About UML class = diagrams at http://www.rational.com/uml
About XML: http://www.xml.com/axml/axml.h= tml
(XML =3D eXtensible Markup Language is a W3C Recommendation,i.e., it is = a standard.)
 

Read about the Law of = Demeter:
You can play by 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?LawOf= Demeter

Extra credit = assignment: Read the above web page = carefully and write a response to this wiki webpage. I think that some of the authors = make incorrect statements and I believe that the DJ tool is not known to the authors. This is a suitable extra credit assignment after the 5th week = of classes.


PART A:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D
 

This homework is about = reverse engineering of Java programs into an object-oriented design.
Reverse engineering means to figure out the design from the program = text.
 

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 DemeterJ from the files tree.cd and tree.beh. While = you study the Java programs, you also learn how DemeterJ 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/X= ML/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 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 reverse = engineering effort with file Tree.java.
Most of the organization of this file is described in file tree.cd. =

Answer the following = questions:

1. Draw a UML class = diagram for the java source files in $SD/hw/1/binary-tree/gen. (For information on = UML, see http://www.rational.com/uml/) =

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: =

--------           &n=
bsp;       =
--------
|  =
A   |           &n=
bsp;    1  =
|  B   |
|      | =
----------------->|      |
--------            &n=
bsp;   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.

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D
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.we= bgain.com/products/structure_builder/
 

They allow you to use = their tool for free during 30 days. If you want to give it a try (many = students do), download the Enterprise edition. The Enterprise edition is the most = powerful of the three available editions and has good support for Enterprise Java = Beans.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

2. Describe the = behavior of the program in English.
Try to summarize the program as much as possible. Do not just translate = each line in the program into English, i.e. SummingVisitor s =3D = SummingVisitor.parse("0"); =3D> Declare SummingVisitor s and set it to whatever returns from = calling SummingVisitor.parse method with "0" as argument.  Try to describe the overall = behavior of the methods. Focus on these methods:
sum_labels()
print_leftTrees()
print_allTrees()
and the methods they call.

Here is a start:
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 belonging to = Webgain (it is freely available at the JavaCC home page:  http://www.webgain.com/= products/java_cc/). The output produced by the program is in file out.

Example start of an = answer:
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 ...



PART B:

Has two subparts: B.1: = do points 1-2 as in part A, but
now reverse-engineer the program in

$SD/hw/1/graph =


NOTE ABOUT PARTS A AND B:

You can answer the = questions by studying the files of the form
*.cd and *.beh. In addition, you should study the generated Java code = (in the gen directory) 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. For = example in the JAXB approach by SUN mentioned earlier there is a separate file that = allows you to control the details of code generation. DemeterJ uses a fixed = method.

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.e= du/research/demeter/DJ/
 

and get a basic = understanding of the package.

Find the unknowns in = the following Java program: The program prints the city where an employee = lives. You should find the UNKNOWNs by using knowledge from your Java book and = by what is in the DJ package documentation. Only after you have found all the = UNKNOWNs you may want to run the Java program.

// Main.java
import =
edu.neu.ccs.demeter.dj.*;
class Main {
  static =
public void main(String args[]) throws Exception {
 
  &nb=
sp; // Build object
    Employee e =3D new =
Employee(
      new =
UNKNOWN1(
        new =
UNKNOWN2(
         =
; new =
UNKNOWN3(
         =
;   new =
String("Boston")))),
      =
new UNKNOWN4(),
      new =
Date());
 
  &nb=
sp; ClassGraph cg =3D buildClassGraph();
    =
System.out.println("City where Employee =
lives");
    =
System.out.println(e.get_city(cg));
    =
System.out.println("City where Employee lives: UNKNOWN5 =
");
    =
System.out.println(e.UNKNOWN6.UNKNOWN7.city.UNKNOWN8);
 
  &nb=
sp; System.out.println("DONE");
  =
}
 
  public =
static ClassGraph UNKNOWN9() {
   ClassGraph =
cg=3Dnew  ClassGraph(true,false);
   // true: =
include all fields 
   // false: do NOT include =
all non-void no-argument methods
  
  =
System.out.println("The UNKNOWN10 version is: " + =
cg.getVersion());
  =
System.out.println("UNKNOWN11" + =
"=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D");
  =
System.out.println(cg);
  System.out.println("end =
class graph " + =
"=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D");
  return =
cg;
 }
 
}
 
// 
<= pre>import edu.neu.ccs.demeter.dj.*;
class UNKNOWN12 =
{
  UNKNOWN13(PersonalInfo personalInfo_, Date d, Date a) =
{
    personalInfo =3D =
UNKNOWN14;
    departure =3D =
UNKNOWN15;
    arrival =3D =
UNKNOWN16;
  }
  PersonalInfo =
personalInfo;
  Date arrival;
  Date =
departure;
  String get_city(ClassGraph cg) =
{
    return (String) =
cg.UNKNOWN17(this,
    "from Employee =
through City to java.lang.String");
  =
}
}
 
// =
PersonalInfo.java
import =
edu.neu.ccs.demeter.dj.*;
class PersonalInfo =
{
  Address address; 
  =
PersonalInfo(Address address_) {
    address =
=3D address_;
  }
}
 
 
// =
Address.java
import edu.neu.ccs.demeter.dj.*;
class =
Address {
  Address(City city_) =
{
    city =3D city_;
  =
}
  City city;
}
 
// =
City.java
import edu.neu.ccs.demeter.dj.*;
class =
City {
  City(String name_) =
{
    name =3D name_;
  =
}
  String name;
}
 
 
// =
Date.java
class Date {
}
 
 

The DJ version is: DJ version 0.8.2
The class graph = is=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D
Address =3D <city> City extends java.lang.Object.
City =3D <name> java.lang.String extends java.lang.Object.
java.lang.Object : City | Address | java.lang.String | Date | = PersonalInfo | Employee | Main common .
java.lang.String =3D extends java.lang.Object implements = java.io.Serializable, java.lang.Comparable.
java.io.Serializable : java.lang.String common .
java.lang.Comparable : java.lang.String common .
Date =3D extends java.lang.Object.
Employee =3D <personalInfo> PersonalInfo <arrival> Date <departure> Date extends java.lang.Object.
PersonalInfo =3D <address> Address extends java.lang.Object.
Main =3D extends java.lang.Object.
java.util.Collection =3D <elements> java.lang.Object.
edu.neu.ccs.demeter.dj.Collection =3D <elements> java.lang.Object. =
end class graph = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D
City where Employee lives
UNKNOWN18
City where Employee lives: bad way
UNKNOWN19
DONE
 

To provide the = answers,
use the file $SD/hw/1/UNKNOWNs
 

An UNKNOWN may be = multiple words.


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: htt= p://www.ccs.neu.edu/research/demeter/DJ/docs/install.html
 

If you use the CCS = .software file, use: CLASSPATH=3D.:/proj/demsys/demjava/rt.jar =

Turn in the output = produced produced by running the program you compiled.


PART E:
Read the Jan/Feb 2001 MIT Technology Review article http://www= .techreview.com/magazine/jan01/tr10_toc.asp about the 10 most promissing technologies that will change the world. = Read the entry: Untangling Code: http:= //www.techreview.com/magazine/jan01/tr10_kiczales.asp

Answer the following = question: How is Aspect-Oriented Programming called at Northeastern University = according to the article?



Submission
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Please follow the following rules:
 

WHERE
For paper based submissions bring your hw solutions to class or drop it = off at the office hours.

ONE SUBMISSION ONLY = PER HOMEWORK
Please submit only once when you are done or on the due date,submit a = partial solution.

You may turn in your = hw for full credit up to two working days late. This means, if it is due on = Thursday, you can turn it in the following Monday. If it is due on day x, it means = 4.30 pm on that day.

For late homework we = will deduct 20% per day late, unless you present a very good reason to the = teaching assistant.



The Java programs used in this homework have been generated by = DemeterJ.



 
 

1. What kind of preparation do I need for this course?
Experience with object-oriented design and programming is an absolute prerequisite.
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. = For all work you can use any machine of your choice which runs the latest = version of Java. But you are responsible for installing the necessary software on = your own machine.

2. What am I going to do if I join the class late?
All messages which I send to the class are archived in http://w= ww.ccs.neu.edu/home/lieber/com1205/w02/archive/ If you join the class late, you can read that archive to get up-to-date. =

3. How to download DJ and DemeterJ

The instructions for downloading DJ and DemeterJ are at: htt= p://www.ccs.neu.edu/research/demeter/DJ/docs/install.html

4. Where can I find the instructions for DemeterJ?
DemeterJ is not needed for this homework, but if you are curious, the = instructions are at URL:
 

http://www.= ccs.neu.edu/research/demeter/DemeterJava/

5. How can I do my homework on my own computer? 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. In each class usually several students = use Windows or Linux to do their homework on their own machine. =


Blackboard (http://blackboard.neu.edu) will = be used mainly for posting of grades, posting of sample solution set, assignment = due dates and logging of special announcements.

o        Create a new student account following the directions on the main = page

o        Login into your blackboard account: http://www.edtech.neu.edu/blackboard/Bb5/login/login.html<= /a>

o        Enroll in the class: Courses > Computer Science > Winter 2002 > Software = Design and Development (Enroll)

o        Check assignment due dates under the Assignments menu

o        Check Sample Solutions under the Course Documents menu.