TIG015 WEEKLY 5

From Juneday education
Jump to: navigation, search

About

This week's hand-in is based on the following chapters (and all preceding chapters):

Therefore, we will investigate the source code from the systemet.jar API and see if we can find any constructors and methods and compare those to the online documentation of the same API.

With this information, we'll see if we can use the constructors and methods found only by reading the API.

Files to hand in

answer_weekly_05.zip containing some files and answer_weekly_05.txt (the latter should also contain your name!).

Tasks

As usual, create a fresh directory, e.g. weekly05 and work from there with the tasks for this weekly assignment.

Get the latest systemet.jar and extract it

Enter the weekly05 directory (which you just created).

Download the latest systemet.jar file and extract it in your weekly05 directory.

Expand using link to the right to see download help.

You can use get_latest_jar.sh to get the latest JAR file. As usual you need to fix the permissions on the script before you can run it.

Identify constructors in the online API documentation

Open a browser and point it to the online API for the Systemet files. Browse through the classes (or interfaces - we'll learn about interfaces later in the course, so don't worry) of the API and identify which classes declare constructors.

If you have viewed this API before, make sure you reload it in order to get the latest version, if the API has changed.

In the current version of the API, there is only one class which has a public constructor. Which is it?

Write the answer in your answer_weekly_05.txt file.

Expand using link to the right to see download help.

The online API has a frame to the bottom left listing "All classes". This is the fastest way to go through all the classes one-by-one.

Investigating all classes one-by-one, you will look for a header listing all the constructors (if any). The structure of the class page in the javadoc documentation system (used to generate the online documentation) has the following section:

  • Field Summary
  • Constructor Summary
  • Method Summary

If the "Constructor Summary" section is missing, it means that the class has no public constructors.

Look at the source code and investigate the constructor

Open the source code for the class with the public constructor and see if you can find the code for the constructor.

Write your answers in your answer_weekly_05.txt file.

What are the parameters to the constructor? (This is shown also in the API documentaion)

What does the code in the constructor block do with the parameters?

Now, think about the situation that we would have if we decided to evolve the API and add more parameters to the constructor. At some point, the constructor becomes hard to manage - perhaps the situation already is a little messy. There is a so called design pattern one could use, as an alternative to a constructor with too many parameters. It is called "Builder". If you'd like, you can search online for the Builder design pattern, or read about it in our wiki on this page. This might be introduced in a future course. We just wanted you to know about a possible solution for replacing constructors with too many parameters!

Identify methods in the Product class

Open the source code file Product.java in an editor.

How many methods can you find in the class?

How many of the methods have an empty parameter list?

Note: a constructor is NOT a method, regardless of what books and your colleagues may say.

Which method has the most parameters?

How many occurrences of the text @Override can you find?

Note: the term override actually refers to replacing an existing method defined somewhere else. The @Override is a hint to the compiler (javac) to make sure that this overriding is done correctly.

Find out, by reading the Product API, what class actually defines these overridden methods