|
|
|
02115 Java Programming |
Autumn 2011 |
Week plan #4
For the week 19. September - 23. September
Preparations for the week
The lectures of the last week has given a fair coverage of sections
6.1 - 6.4 of Chapter 6 and has shown how to record a test and thus
automatically build a simple (maybe too simple) test method for
double booking. Also it was introduced how to take advantage of
the setUp()
method to hold fixtures (that are statements
which will be executed before every test method is activated).
Details on handling fixtures - section 6.4.4 (pages 185-186) -
should be studied carefully. And as told on the plan for last week in
the section After the lectures: Don't forget the remaining
parts of the chapter (pages 186-200). Those parts could be useful
in relation to doing the coming mandatory assignment.
The situation for the subjects of Chapter 7 is that the practical
things have been demonstrated together with some reasons for making
the improvements of the design and implementation of the
zool game. But I left out the general concepts and
much of the important background reasoning:
- Section 7.7 (starting at page 217) on
Responsibility-driven design focuses on the idea that each
class should be responsible for handling its own data, which leads
to a low degree of coupling.
- The importance of following the concept of
Localizing change, section 7.8, page 220, is stated. When
followed later modifications require changes of only one class.
- Implicit coupling is when one class
depends on internal information of another, but this dependence
is not obvious, section 7.9 (pages 220-224). Thus it's often
a problem to avoid implicit coupling.
- The advices on Thinking ahead and on achieving
Cohesion, pages 224-228.
- The very important stated aspects of refactoring and particular
the illustrative example of section 7.12.2 (pages 228-232).
- The summary of Design guidelines, section 7.14 (page 237).
- The concept of and implications of using class methods, section 7.15
(pages 238-240), including the
main()
method,
section 7.15.2.
In the last week one of the questions was:
How to avoid duplicate code within the
same class ?
Use a private auxiliary method holding the common code.
In this week one qustion is:
How to avoid duplicate code and fields in a number of
related classes ?
Use inheritance from a common super class.
Inheritance is the subject of Chapters 8 and 9. To be introduced just study
Chapter 8 of BK to the following extent:
- Chapter 8: 8.1 - 8.5; pages 245-264:
- Read the chapter introduction and section 8.1,
pages 245-256
Work through the exercises 8.1 and 8.2
- Read section 8.2, pages 256 and 257, to be introduced to
inheritance. Figure 8.5 on page 256 shows common
fields and methods extracted from classes CD and DVD,
Figure 8.2 - page 247, and put into the common super class
Item
- Read section 8.3, pages 257 and 258
- Read section 8.4, pages 258-262
Work through the exercises 8.4 and 8.5
- Read section 8.5, pages 262-264
The lectures
We will cover selected parts of the textbooks, primarily the following
parts of BK
- Chapter 8, pages 245-274
- Chapter 9, pages 276-298
Exercises at the PC's
Exercises are taken solely from the BK textbook:
- Chapter 8:
Exercises 8.7, 8.8, 8.12 and 8.13, and (for the more
experienced student) 8.16
- Chapter 9:
Exercises 9.3, 9.4 and 9.7, and (for the more
experienced student) 9.9 - 9.11
How to run Java Precisely examples using BlueJ
Say, you want to incorporate Example60 of the PS
textbook as a BlueJ project:
- Open BlueJ and ask for New Project
- Give the project a name - as e.g. Example60
- Then Close the project
- In the file system the project Example60 is a
directory to which you has to copy the file
Example60.java
from the collection of ready-to-run
programs from the Java Precisely textbook
- Then in BlueJ choose Open Project on project
Example60 which now holds the class Example60
- Compile the Java class
- Right click on Example60 and select the method
void main(String[])
to execute
After the lectures
The lectures has not covered all details of the chapters 8 and 9 of
BK. Work through the missing parts and do the exercises missed
at the exercise class, refer to the section above, with the
supplements mentioned below as a minimum.
At the end of this week you are supposed to be familiar with the
following parts of the BK textbook:
- Chapter 8: Pages 245-275. Also remember to read page 274-275
with the
Summary, including the terms and the Concept summary in order to
check that you are familiar with what has been introduced in the
chapter. If some terms and/or concepts are not familiar to you, then
look up the descriptions in the chapter.
Do Exercise 8.11 (page 265)
The implications of inheritance are important as can be
read in sections 8.7 and 8.8 (pages 265-271)
Autoboxing and wrapper classes are introduced in section 8.9
of the BK textbook. Relate to section 5.4 of PS
Section 8.10 (page 273) relates inheritance to the Java library
definitions of the collections classes - relate that desciption
to the overview of PS (page 92, lower part)
Section 8.11 (pages 273-275)
Do Exercise 8.18
- Chapter 9: Pages 276-299.
Be aware of the methods declared in the ultimate super class
of Java, the Object
class:
toString
in section 9.7, pages 287-290
Relate to PS, page 10, fifth bullet
equals
and hashCode
in section
9.8, pages 290-292
Relate to PS, section 22.8 (page 104) and the
Examples 133 and 134, page 105
Don't forget the last sections of the chapter (pages
292-299)
Work through Exercises 9.12 and 9.13
Besides the above mentioned sections of the PS textbook
read the following sections:
- Section 5, the first four subsections, pages 4 and 5
- Section 9.5, pages 22 and 23, with exclusion of what is stated about
o.super(
actual-list);
when C
's superclass B
is an
inner class
- the throws-clause
Abstract classes are not yet covered by the BK textbook,
but besides that
Example 27 should not cause any problems.
Read and run Example 28
Jens Thyge Kristensen,
Email: jtk@imm.dtu.dk
Newest edition:   14. September (The section 'How to run Java
Precisely examples using BlueJ' has been added)
Previous editions:
- 13. September
- 8. April (just the heading and footing)