CM10134 / CM50147 CM10134 / CM50147 Pr Prog ogramming I mming I - - PDF document

cm10134 cm50147 cm10134 cm50147 pr prog ogramming i mming
SMART_READER_LITE
LIVE PREVIEW

CM10134 / CM50147 CM10134 / CM50147 Pr Prog ogramming I mming I - - PDF document

CM10134 / CM50147 CM10134 / CM50147 Pr Prog ogramming I mming I Lecture Handouts Dr. Marina De Vos 2005-2006 Programming 1 06/10/2005 Course Contents CM10134-CM50147 Introduction to object-oriented Programming I programming


slide-1
SLIDE 1

CM10134 / CM50147 CM10134 / CM50147 Pr Prog

  • gramming I

mming I

Lecture Handouts

  • Dr. Marina De Vos

2005-2006

slide-2
SLIDE 2

Programming 1 06/10/2005 Lecture 1a: Introduction 1

CM10134-CM50147 Programming I Basic Programming in Java

Marina De Vos

06/10/2005 Lecture 1a: Introduction 2

Course Contents

  • Introduction to object-oriented

programming…

  • …with a strong software engineering

foundation…

  • …aimed at producing and maintaining

large, high-quality software systems.

06/10/2005 Lecture 1a: Introduction 3

Buzzwords

interface

javadoc encapsulation coupling cohesion polymorphic method calls inheritance mutator methods collection classes

  • verriding

iterators responsibility-driven design aggregation design patterns reuse abstraction

06/10/2005 Lecture 1a: Introduction 4

Goals

  • Sound knowledge of programming

principles

  • Sound knowledge of object-orientation
  • Able to critically assess the quality of a

(small) software system

  • Able to implement a small software system

in Java

06/10/2005 Lecture 1a: Introduction 5

Course Text

David J. Barnes & Michael Kölling Objects First with Java A Practical Introduction using BlueJ Pearson Education, 2003 ISBN 0-13-044929-6.

06/10/2005 Lecture 1a: Introduction 6

Additional Book

Bruce Eckel Thinking in Java, 3rd Edition Prentice-Hall, 2002 ISBN 031002872 Free online copy: “http://www.mindview.net/Books/TIJ/”

slide-3
SLIDE 3

Programming 1 06/10/2005 Lecture 1a: Introduction 2

06/10/2005 Lecture 1a: Introduction 7

Webpage

The course webpage is at

www.cs.bath.ac.uk/~mdv/courses/prog1.html

Please check it regularly. It will be used for announcements and distribution of material for lectures, labs, coursework.

06/10/2005 Lecture 1a: Introduction 8

Mailing lists

  • programming1@bath.ac.uk

the general mailing list for this unit.

  • tutors-programming1@cs.bath.ac.uk

to contact the tutors of this unit and to submit lab sheets in case of illness.

06/10/2005 Lecture 1a: Introduction 9

Course overview (1)

  • Objects and classes
  • Understanding class definitions
  • Object interaction
  • Grouping objects
  • More sophisticated behaviour - libraries
  • Well-behaved objects - testing, maintaining,

debugging

  • Designing classes
06/10/2005 Lecture 1a: Introduction 10

Course overview (2)

  • Inheritance
  • Polymorphism
  • Extendable, flexible class structures
  • Handling errors
  • Designing applications
06/10/2005 Lecture 1a: Introduction 11

Passing this Unit

  • Exam

– Answer three questions on theoretical and practical issues of programming.

  • Coursework

– Write four medium-sized programs in an object

  • riented way using the design methods we discussed.

In order to be allowed to sit the exam and to do the coursework 7 exercise sheets have to be satisfactory completed.

slide-4
SLIDE 4

Programming 1 06/10/2005 Lecture 1b: Objects and Classes 1

Objects and Classes

First Programming Concepts

06/10/2005 Lecture 1b: Objects and Classes 2

Fundamental Concepts

  • object
  • class
  • method
  • parameter
  • data type
06/10/2005 Lecture 1b: Objects and Classes 3

Objects and Classes

  • Objects

– represent ‘things’ from the real world, or from some problem domain (example: “the red car down there in the car park”)

  • Classes

– represent all objects of a kind (example: “car”)

Objects represent individual instantiations of the

  • class. Object are instantiated.
06/10/2005 Lecture 1b: Objects and Classes 4

Objects and Classes in BlueJ

06/10/2005 Lecture 1b: Objects and Classes 5

Things we can do with Objects

06/10/2005 Lecture 1b: Objects and Classes 6

Things we can do with Objects

slide-5
SLIDE 5

Programming 1 06/10/2005 Lecture 1b: Objects and Classes 2

06/10/2005 Lecture 1b: Objects and Classes 7

Methods and Parameters

  • Objects/classes have operations which can be
  • invoked. They are called methods
  • void moveHorizontal(int distance) is called the

signature of the methods

  • The collection of methods of a class is referred to

as the interface of that class

  • methods may have parameters to pass additional

information needed to execute

  • Methods are called or invoked
06/10/2005 Lecture 1b: Objects and Classes 8

Data Types

  • Parameters have types. A type defines what

kinds of values a parameter can take.

  • Defining a class defines a type
  • In Java, everything has a type.
  • Java is strongly typed language
  • Examples of types: int, String, Circle, …
06/10/2005 Lecture 1b: Objects and Classes 9

Other Observations

  • many instances can be created from a single

class

  • an object has attributes: values stored in

fields.

  • the class defines what fields an object has,

but each object stores its own set of values.

  • These set of values is called the state of the
  • bject.
06/10/2005 Lecture 1b: Objects and Classes 10

State

06/10/2005 Lecture 1b: Objects and Classes 11

Two Circle Objects

06/10/2005 Lecture 1b: Objects and Classes 12

Object Interaction

slide-6
SLIDE 6

Programming 1 06/10/2005 Lecture 1b: Objects and Classes 3

06/10/2005 Lecture 1b: Objects and Classes 13

Source Code

  • Each class has source code (Java code)

associated with it that defines its details (fields and methods).

  • In other words, it determines the structure

and the behavior of each of its instance.

  • This source code is compiled and

interpreted by Java.

06/10/2005 Lecture 1b: Objects and Classes 14

Return Values

  • Methods may return a result via a return

value.

  • Example: String getName()

– This method returns a String.

  • Example: void changeName()

– Void indicates that this method does not return anything

06/10/2005 Lecture 1b: Objects and Classes 15

Developing Java Programs

  • To learn to develop Java programs, one

needs to learn how to write class definitions, including fields and methods, and how to put these classes together as well

  • During the rest of this unit we will deal with

these issues in more detail

06/10/2005 Lecture 1b: Objects and Classes 16

Terms

  • Object
  • Instance
  • State
  • Compiler
  • Virtual Machine
  • Method Calling
  • Class
  • Method
  • Return Value
  • Signature
  • Parameter
  • Type
  • Source Code
slide-7
SLIDE 7

Programming 1 13/10/2005 Lecture 2: Understanding Class Definitions 1

Understanding class definitions

Looking inside classes

13/10/2005 Lecture 2: Understanding Class Definitions 2

Main concepts to be covered

  • fields
  • constructors
  • methods
  • parameters
  • assignment statements
  • conditional statements
13/10/2005 Lecture 2: Understanding Class Definitions 3

Ticket machines – an external view

  • Exploring the behavior of a typical ticket

machine.

– Use the naive-ticket-machine project. – Machines supply tickets of a fixed price.

  • How is that price determined?

– How is ‘money’ entered into a machine? – How does a machine keep track of the money that is entered? – How is a ticket provided?

13/10/2005 Lecture 2: Understanding Class Definitions 4

Resulting Fields

13/10/2005 Lecture 2: Understanding Class Definitions 5

Resulting Methods

13/10/2005 Lecture 2: Understanding Class Definitions 6

Ticket machines – an internal view

  • Interacting with an object gives us clues

about its behavior.

  • Looking inside allows us to determine how

that behavior is provided or implemented.

– Looking at the source code

  • All Java classes have a similar-looking

internal view.

slide-8
SLIDE 8

Programming 1 13/10/2005 Lecture 2: Understanding Class Definitions 2

13/10/2005 Lecture 2: Understanding Class Definitions 7

The Source Code

13/10/2005 Lecture 2: Understanding Class Definitions 8

Basic class structure

public class TicketMachine { Inner part of the class omitted. } public class ClassName { Fields Constructors Methods }

The outer wrapper

  • f TicketMachine

The contents of a class

13/10/2005 Lecture 2: Understanding Class Definitions 9

Comments/Documentation

  • Comments make source code easier to read

for humans. No effect on the functionality.

  • Three sorts:

– // comment: single-line comments – /* comments */: multiple-lines – more detail – /** */: similar to previous, but used when documentation software is used.

13/10/2005 Lecture 2: Understanding Class Definitions 10

Fields

  • Fields store values for

an object.

  • They are also known as

instance variables.

  • Use the Inspect option

to view an object’s fields.

  • Fields define the state
  • f an object.
public class TicketMachine { private int price; private int balance; private int total; Constructor and methods omitted. } private int price;

visibility modifier type variable name

13/10/2005 Lecture 2: Understanding Class Definitions 11

Constructors

  • Constructors initialize

an object.

  • Then assign the

necessary memory to the created object

  • They have the same

name as their class.

  • They store initial values

into the fields.

  • They often receive

external parameter values for this.

public TicketMachine(int ticketCost) { price = ticketCost; balance = 0; total = 0; } 13/10/2005 Lecture 2: Understanding Class Definitions 12

Passing data via parameters

slide-9
SLIDE 9

Programming 1 13/10/2005 Lecture 2: Understanding Class Definitions 3

13/10/2005 Lecture 2: Understanding Class Definitions 13

Parameters

  • Parameter names inside a constructor or

method are referred to as Formal Parameters.

  • Parameter values provided from the outside

are referred to as Actual Parameters.

  • In the example: ticketCost is a formal

parameter and 500 is an actual parameter.

13/10/2005 Lecture 2: Understanding Class Definitions 14

Space

  • The ticketCost box in the object

representation is only created when the constructor is executed.

  • Extra temporarily storage is provided to

store a value for ticketCost. This is called the constructor space or method space.

  • Values can only be used during the

execution.

13/10/2005 Lecture 2: Understanding Class Definitions 15

Scope and Lifetime

  • The scope of a variable/parameter defines the

section of the code from where it can be accessed.

  • For instance variables this is the entire class.
  • For parameters, this is the constructor or method

that declares it.

  • Trick: find the enclosing {}, this is the scope
  • The lifetime of a variable/parameter describes how

long the variable continues to exist before it is destroyed.

13/10/2005 Lecture 2: Understanding Class Definitions 16

Assignment

  • Values are stored into fields (and other

variables) via assignment statements:

– variable = expression; – price = ticketCost;

  • Both sides of the assignment should have

the same type, e.g. int, double, String, …

  • A variable stores a single value, so any

previous value is lost.

13/10/2005 Lecture 2: Understanding Class Definitions 17

Accessor methods

  • Methods implement the behavior of objects.
  • Accessors provide information about an
  • bject.
  • Methods have a structure consisting of a

header and a body.

  • The header defines the method’s signature.

public int getPrice()

  • The body encloses the method’s statements.
13/10/2005 Lecture 2: Understanding Class Definitions 18

Accessor methods

public int getPrice() { return price; }

return type method name parameter list (empty) start and end of method body (block) return statement visibility modifier

slide-10
SLIDE 10

Programming 1 13/10/2005 Lecture 2: Understanding Class Definitions 4

13/10/2005 Lecture 2: Understanding Class Definitions 19

Mutator methods

  • Have a similar method structure: header and

body.

  • Used to mutate (i.e., change) an object’s

state.

  • Achieved through changing the value of one
  • r more fields.

– Typically contain assignment statements. – Typically receive parameters.

13/10/2005 Lecture 2: Understanding Class Definitions 20

Mutator methods

public void insertMoney(int amount) { balance += amount; }

return type (void) method name parameter visibility modifier assignment statement field being changed

13/10/2005 Lecture 2: Understanding Class Definitions 21

Printing from methods

public void printTicket() { // Simulate the printing of a ticket. System.out.println("##################"); System.out.println("# The BlueJ Line"); System.out.println("# Ticket"); System.out.println("# " + price + " cents."); System.out.println("##################"); System.out.println(); // Update the total collected with the balance. total += balance; // Clear the balance. balance = 0; }

13/10/2005 Lecture 2: Understanding Class Definitions 22

Output

13/10/2005 Lecture 2: Understanding Class Definitions 23

Reflecting on the ticket machines

  • Their behavior is inadequate in several

ways:

– No checks on the amounts entered. – No refunds. – No checks for a sensible initialization.

  • How can we do better?

– We need more sophisticated behavior.

13/10/2005 Lecture 2: Understanding Class Definitions 24

Making choices

public void insertMoney(int amount) { if(amount > 0) { balance += amount; } else { System.out.println("Use a positive amount: " + amount); } }

slide-11
SLIDE 11

Programming 1 13/10/2005 Lecture 2: Understanding Class Definitions 5

13/10/2005 Lecture 2: Understanding Class Definitions 25

Making choices

if(perform some test) { Do the statements here if the test gave a true result } else { Do the statements here if the test gave a false result }

‘if’ keyword boolean condition to be tested - gives a true or false result actions if condition is true actions if condition is false ‘else’ keyword

13/10/2005 Lecture 2: Understanding Class Definitions 26

Boolean Tests

  • == : equality
  • > : greater than
  • < : less than
  • =< : less or equal than
  • >= : greater or equal than
  • != : not equal
13/10/2005 Lecture 2: Understanding Class Definitions 27

Local variables

  • Fields are one sort of variable.

– They store values through the life of an object. – They are accessible throughout the class.

  • Methods can include shorter-lived variables.

– They exist only as long as the method is being executed. – They are only accessible from within the method.

13/10/2005 Lecture 2: Understanding Class Definitions 28

Local variables

public int refundBalance() { int amountToRefund; amountToRefund = balance; balance = 0; return amountToRefund; } A local variable

No visibility modifier

13/10/2005 Lecture 2: Understanding Class Definitions 29

Review

  • Class bodies contain fields, constructors and

methods.

  • Fields store values that determine an
  • bject’s state.
  • Constructors initialize objects.
  • Methods implement the behavior of objects.
  • Constructors are methods which do not

return anything.

13/10/2005 Lecture 2: Understanding Class Definitions 30

Review

  • Fields, parameters and local variables are all

variables.

  • Fields persist for the lifetime of an object.
  • Parameters are used to receive values into a

constructor or method.

  • Local variables are used for short-lived

temporary storage.

slide-12
SLIDE 12

Programming 1 13/10/2005 Lecture 2: Understanding Class Definitions 6

13/10/2005 Lecture 2: Understanding Class Definitions 31

Review

  • Objects can make decisions via conditional

(if) statements.

  • A true or false test allows one of two

alternative courses of actions to be taken.

13/10/2005 Lecture 2: Understanding Class Definitions 32

Terms

  • Instance variables
  • Local variables
  • Parameters
  • Formal Parameters
  • Actual Parameters
  • Scope
  • Lifetime
  • Constructors
  • Methods
  • If-statement
  • Assignment
  • =
  • +=
  • <=, >=, <, >, !=, ==
slide-13
SLIDE 13

Programming 1 20/10/2005 Lecture 3: Object Interaction 1

Object interaction

Creating cooperating objects

20/10/2005 Lecture 3: Object Interaction 2

Main concepts to be covered

  • Abstraction
  • Modularization
  • Class and Object Diagrams
  • Call-by-reference and Call-by-value
  • Overloading
  • Internal and External method calls
  • this keyword
  • Debugging
20/10/2005 Lecture 3: Object Interaction 3

A digital clock

20/10/2005 Lecture 3: Object Interaction 4

Abstraction and modularization

  • Abstraction is the ability to ignore details
  • f parts to focus attention on a higher level
  • f a problem.
  • Modularization is the process of dividing a

whole into well-defined parts, which can be built and examined separately, and which interact in well-defined ways.

20/10/2005 Lecture 3: Object Interaction 5

Modularizing the clock display

One four-digit display? Or two two-digit displays?

20/10/2005 Lecture 3: Object Interaction 6

Implementation: NumberDisplay

public class NumberDisplay { private int limit; private int value; Constructor and methods omitted. }

slide-14
SLIDE 14

Programming 1 20/10/2005 Lecture 3: Object Interaction 2

20/10/2005 Lecture 3: Object Interaction 7

Implementation ClockDisplay

public class ClockDisplay { private NumberDisplay hours; private NumberDisplay minutes; Constructor and methods omitted. }

20/10/2005 Lecture 3: Object Interaction 8

Object diagram

20/10/2005 Lecture 3: Object Interaction 9

Class diagram

20/10/2005 Lecture 3: Object Interaction 10

Diagrams

  • Class Diagrams

– Shows the classes of an application and the relationships between them – Gives information about the source code – Static view of the program

  • Object Diagrams

– Shows objects and their relationships at one moment in time during the execution of the program – Dynamic view of the program

20/10/2005 Lecture 3: Object Interaction 11

BlueJ and Diagrams

20/10/2005 Lecture 3: Object Interaction 12

Primitive types vs. object types

  • Java defines two very different kinds of

type: primitive types and object types.

  • Primitive types are predefined by Java.
  • Object types originate from classes.
  • Variables and parameters store references to
  • bjects.
  • The primitive types are non-object types.
slide-15
SLIDE 15

Programming 1 20/10/2005 Lecture 3: Object Interaction 3

20/10/2005 Lecture 3: Object Interaction 13

Primitive types vs. object types

32

  • bject type

primitive type SomeObject obj; int i;

20/10/2005 Lecture 3: Object Interaction 14

Primitive types vs. object types

32

SomeObject a; int a; SomeObject b;

32

int b; b = a;

20/10/2005 Lecture 3: Object Interaction 15

Call-by-reference and Call-by-value

  • There are two ways of passing arguments to

methods in many programming languages: call-by-value and call-by-reference.

  • Call-by-value: A copy of the actual

parameter is passed to the formal parameter

  • f the called method. Any change made to

the formal parameter will have no effect on the actual parameter.

20/10/2005 Lecture 3: Object Interaction 16

Call-by-reference and Call-by-value

  • Call-by-reference: the caller gives the called

method the ability to directly access to the caller’s data and to modify that data if the called method so chooses.

  • Java uses call-by-value for primitive data

types and call-by-reference for object types.

20/10/2005 Lecture 3: Object Interaction 17

Source code: NumberDisplay

public class NumberDisplay { private int limit; private int value; public NumberDisplay(int rollOverLimit) { limit = rollOverLimit; value = 0; }

20/10/2005 Lecture 3: Object Interaction 18

Source code: NumberDisplay

public int getValue() { return value; } public void setValue(int replacementValue) { if((replacementValue >= 0) && (replacementValue < limit)) value = replacementValue; }

slide-16
SLIDE 16

Programming 1 20/10/2005 Lecture 3: Object Interaction 4

20/10/2005 Lecture 3: Object Interaction 19

Logical Operators

  • && : and, operands are tested, left to right,

until conclusion can be reached

  • || : or, operands are tested, left to right, until

conclusion can be reached

  • ! : not
  • & : and, both operands are tested
  • | : or, both operands are tested
20/10/2005 Lecture 3: Object Interaction 20

Source code: NumberDisplay

public String getDisplayValue() { if(value < 10) return "0" + value; else return "" + value; } public void increment() { value = (value + 1) % limit; } }

20/10/2005 Lecture 3: Object Interaction 21

String Concatenation

  • Addition:

– 12 + 24

  • String Concatenation:

– “Java” + “with BlueJ” -> “Javawith BlueJ” – “answer: ” + 42 -> “answer: 42”

20/10/2005 Lecture 3: Object Interaction 22

String toString() method

  • String toString() method: Java provides a way of

transforming every Object into a String. To tailor this to your own preference write a method toString() returning a String representation of your class/object.

public String toString() { return “value: “ + value + “ with limit ” + limit; }

20/10/2005 Lecture 3: Object Interaction 23

The Modulo Operator

  • % : the modulo operator calculates the

remainder of an integer division

– 27 & 4 -> 3

  • Division in Java: if both arguments are

integers, division will result in an integer.

– double res = 5 / 2 -> res = 2 – double res = 5 / (2.0) or 5 / (2 * 1.0)

  • > res = 2.5
20/10/2005 Lecture 3: Object Interaction 24

Objects creating objects

public class ClockDisplay { private NumberDisplay hours; private NumberDisplay minutes; private String displayString; public ClockDisplay() { hours = new NumberDisplay(24); minutes = new NumberDisplay(60); updateDisplay(); } }

slide-17
SLIDE 17

Programming 1 20/10/2005 Lecture 3: Object Interaction 5

20/10/2005 Lecture 3: Object Interaction 25

Objects creating objects

1. new ClassName(parameter-list)

– It creates a new object of the named class

  • here NumberDisplay
  • this involves creating sufficient memory to store the values
  • f primitive instance variables and references to object

instance variables.

2. It executes the constructor of that class public NumberDisplay new NumberDisplay

(int rollOverLimit)

formal parameter

(24)

actual parameter

20/10/2005 Lecture 3: Object Interaction 26

ClockDisplay object diagram

20/10/2005 Lecture 3: Object Interaction 27

Method Overloading

  • Multiple Constructors of ClockDisplay:

– new Clockdisplay() – new Clockdisplay(hour, minute)

  • It is common for class definitions to contain

alternative versions of constuctors or methods that provide various ways of achieving a particular task via their distinctive sets of parameters.

  • This is known as overloading.
20/10/2005 Lecture 3: Object Interaction 28

Method calling

public void timeTick() { minutes.increment(); if(minutes.getValue() == 0) { // it just rolled over! hours.increment(); } updateDisplay(); }

20/10/2005 Lecture 3: Object Interaction 29

Internal method

/** * Update the internal string that * represents the display. */ private void updateDisplay() { displayString = hours.getDisplayValue() + ":" + minutes.getDisplayValue(); }

20/10/2005 Lecture 3: Object Interaction 30

Method calls

  • internal method calls

updateDisplay(); private void updateDisplay()

  • methodName(parameter-list)
  • external method calls

minutes.increment();

  • object.methodName(parameter-list)
slide-18
SLIDE 18

Programming 1 20/10/2005 Lecture 3: Object Interaction 6

20/10/2005 Lecture 3: Object Interaction 31

Public and Private Methods

  • Public methods:
  • public void increment()
  • can be called externally
  • Private methods
  • private void updateDisplay()
  • can only be called internally
  • used for auxiliary methods
20/10/2005 Lecture 3: Object Interaction 32

The Mail System

20/10/2005 Lecture 3: Object Interaction 33

The this Keyword

public class MailItem { private String from; private String to; private String message; public MailItem(String from, String to, String message) { this.from = from; this.to = to; this.message = message; }

20/10/2005 Lecture 3: Object Interaction 34

The this Keyword

  • this.from = from

– name overloading: the same name is used for two different entities: instance variable and formal parameter. – this is used to go out of the scope of the constructor to class level – this always refers to the current object. – can also used for methods – for internal methods calls and access to instance fields Java automatically inserts this – updateDisplay -> this.updateDisplay

20/10/2005 Lecture 3: Object Interaction 35

Debugging

  • Software is hardly ever written without

making mistakes or bugs.

  • There are two type of bugs:

– syntax: can be traced using the compiler – logical:

  • tracing the program manually
  • using a debugging tool
  • BlueJ provides a debugger
20/10/2005 Lecture 3: Object Interaction 36

Debugging

slide-19
SLIDE 19

Programming 1 20/10/2005 Lecture 3: Object Interaction 7

20/10/2005 Lecture 3: Object Interaction 37

Concepts

  • abstraction
  • modularisation
  • call-by-value
  • call-by-reference
  • logical operators/modulo
  • this
  • class/object diagram
  • primitive types
  • object types
  • object creation
  • overloading
  • internal/external method

calls

  • private methods
  • debugging
slide-20
SLIDE 20

Programming 1 27/10/2005 Lecture 4: Grouping Objects 1

Grouping objects

Collections and iterators

27/10/2005 Lecture 4: Grouping Objects 2

Main concepts to be covered

  • Collections
  • Loops
  • Iterators
  • Arrays
27/10/2005 Lecture 4: Grouping Objects 3

The requirement to group objects

  • Many applications involve collections of
  • bjects:

– Personal organizers. – Library catalogs. – Student-record system.

  • The number of items to be stored varies.

– Items added. – Items deleted.

27/10/2005 Lecture 4: Grouping Objects 4

A personal notebook

  • Notes may be stored.
  • Individual notes can be viewed.
  • There is no limit to the number of notes.
  • It will tell you how many notes are stored.
27/10/2005 Lecture 4: Grouping Objects 5

A personal notebook

27/10/2005 Lecture 4: Grouping Objects 6

Class Libraries

  • Learning to program is to learn how to

reuse code written by other. There is no point in reinventing the wheel.

  • Java comes with a library of useful classes,

which are referred to as the Java API

  • They are organized in packages that follow

a directory structure

slide-21
SLIDE 21

Programming 1 27/10/2005 Lecture 4: Grouping Objects 2

27/10/2005 Lecture 4: Grouping Objects 7

Class Libraries

27/10/2005 Lecture 4: Grouping Objects 8

Class libraries

  • You can access the classes from your code,

using the import statement

– import java.util.Vector; – import java.util.*;

  • Grouping objects is a recurring requirement.

– The java.util package contains classes for doing this. – We will use ArrayList as a first example

27/10/2005 Lecture 4: Grouping Objects 9

Class Libraries

27/10/2005 Lecture 4: Grouping Objects 10

import java.util.ArrayList; /** * ... */ public class Notebook { // Storage for an arbitrary number of notes. private ArrayList notes; /** * Perform any initialization required for the * notebook. */ public Notebook() { notes = new ArrayList(); } ... }

27/10/2005 Lecture 4: Grouping Objects 11

Object structures with collections

27/10/2005 Lecture 4: Grouping Objects 12

Adding a third note

slide-22
SLIDE 22

Programming 1 27/10/2005 Lecture 4: Grouping Objects 3

27/10/2005 Lecture 4: Grouping Objects 13

Features of the collection

  • It increases its capacity as necessary.
  • It keeps a private count (size() accessor).
  • It keeps the objects in order.
  • Details of how all this is done are hidden.

– Does that matter? Does not knowing how prevent us from using it?

27/10/2005 Lecture 4: Grouping Objects 14

Using the collection

public class Notebook { private ArrayList notes; ... public void storeNote(String note) { notes.add(note); } public int numberOfNotes() { return notes.size(); } ... } Adding a new note Returning the number of notes (delegation).

27/10/2005 Lecture 4: Grouping Objects 15

Index numbering

27/10/2005 Lecture 4: Grouping Objects 16

Retrieving an object

Index validity checks Retrieve and print the note public void showNote(int noteNumber) { if(noteNumber < 0) { // This is not a valid note number. } else if(noteNumber < numberOfNotes()) { System.out.println(notes.get(noteNumber)); } else { // This is not a valid note number. } }

27/10/2005 Lecture 4: Grouping Objects 17

Removing an item

public void removeNote(int noteNumber) { if(noteNumber < 0) { // This is not a valid note number, so do nothing. } else if(noteNumber < numberOfNotes()) { // This is a valid note number. notes.remove(noteNumber); } else { // This is not a valid note number, so do nothing. } }

27/10/2005 Lecture 4: Grouping Objects 18

Removal may affect numbering

slide-23
SLIDE 23

Programming 1 27/10/2005 Lecture 4: Grouping Objects 4

27/10/2005 Lecture 4: Grouping Objects 19

Review

  • Collections allow an arbitrary number of
  • bjects to be stored.
  • Class libraries usually contain tried-and-

tested collection classes.

  • Java’s class libraries are called packages.
  • We have used the ArrayList class from

the java.util package.

27/10/2005 Lecture 4: Grouping Objects 20

Review

  • Items may be added and removed.
  • Each item has an index.
  • Index values may change if items are

removed (or further items added).

  • The main ArrayList methods are add,

get, remove and size.

27/10/2005 Lecture 4: Grouping Objects 21

Iteration

  • We often want to perform some actions an

arbitrary number of times.

– E.g., print all the notes in the notebook. How many are there?

  • Most programming languages include loop

statements to make this possible.

  • Java has three sorts of loop statements.

– We will focus on its while loop to begin with.

27/10/2005 Lecture 4: Grouping Objects 22

While loop pseudo code

while(loop condition) { loop body } while(there is at least one more note to be printed) { show the next note }

Boolean test while keyword Statements to be repeated Pseudo-code example to print every note General form of a while loop

27/10/2005 Lecture 4: Grouping Objects 23

A Java example

/** * List all notes in the notebook. */ public void listNotes() { int index = 0; while(index < notes.size()) { System.out.println(notes.get(index)); index++; } } Increment by one

27/10/2005 Lecture 4: Grouping Objects 24

Increments

  • i++ : the value of i is used first before it is

being incremented with one

– a = 5; b = a++; – a == 6; b == 5;

  • ++i: increments i with one, the new value of

i is then used.

– a = 5; b = ++a; – a == 6; b == 6;

slide-24
SLIDE 24

Programming 1 27/10/2005 Lecture 4: Grouping Objects 5

27/10/2005 Lecture 4: Grouping Objects 25

Iterating over a collection

Iterator it = myCollection.iterator(); while(it.hasNext()) { call it.next() to get the next object do something with that object } java.util.Iterator Returns an Iterator

  • bject

public void listNotes() { Iterator it = notes.iterator(); while(it.hasNext()) { System.out.println(it.next()); } }

27/10/2005 Lecture 4: Grouping Objects 26

Iterators

  • An iterator is an object that provides functionality

to iterate over all elements of a collection or container class

  • java.util.Iterator
  • two main methods: hasNext() to check if the

Iterator has more elements and next() to take the next object from the Iterator.

  • You can access an iterator for all java collections.
  • Not all collections can be accessed using indexes.
27/10/2005 Lecture 4: Grouping Objects 27

The auction project

  • The auction project provides further

illustration of collections and iteration.

  • Two further points to follow up:

– The null value. – Casting. Used to store the result of get into a variable:

  • String message = (String) notes.get(0);
27/10/2005 Lecture 4: Grouping Objects 28

The auction project

27/10/2005 Lecture 4: Grouping Objects 29

The Lot Class

public void bidFor(Person bidder, long value) { if((highestBid == null) || (highestBid.getValue() < value)) { // This bid is the best so far. setHighestBid(new Bid(bidder, value)); } else { System.out.println("Lot number: " + getNumber() + " (" + getDescription() + ")" + " already has a bid of: " + highestBid.getValue()); } }

27/10/2005 Lecture 4: Grouping Objects 30

The null Keyword

  • highestBid == null;

– The Java keyword null is used to mean ‘no

  • bject’ when a variable is not currently holding

a reference to a particular object.

  • setHighestBid(new Bid(bidder, value));

– two things are done here:

  • we create a new object Bid
  • we pass this new object immediately to the method
slide-25
SLIDE 25

Programming 1 27/10/2005 Lecture 4: Grouping Objects 6

27/10/2005 Lecture 4: Grouping Objects 31

The Auction Class

public void showLots() { Iterator it = lots.iterator(); while(it.hasNext()) { Lot lot = (Lot) it.next(); System.out.println(lot.getNumber() + ": " + lot.getDescription()); // Include any details of a highest bid. Bid highestBid = lot.getHighestBid(); if(highestBid != null) { System.out.println(" Bid: " + highestBid.getValue()); } else { System.out.println(" (No bid)"); } } } 27/10/2005 Lecture 4: Grouping Objects 32

Type Casting

  • Lot lot = (Lot) it.next();

– the return value of the Iterator method next() is an object of type Object. To store this in an

  • bject of type Lot we need to explicitly convert

it that type. This is called Casting – This can only been done if the objects we have added to the container were originally of type Lot.

27/10/2005 Lecture 4: Grouping Objects 33

Type Casting

  • Collections in Java allow for the storage of

any type of objects. In order to do so it transforms everything you add into an

  • bject of type Object.
  • When retrieving objects from a collection

we normally cast them back into their

  • riginal types.
27/10/2005 Lecture 4: Grouping Objects 34

Wrapper Classes

  • Container classes in Java can only contain
  • bjects.
  • Primitive types can therefore not be added.
  • To solve this, Java provides wrapper

classes: Integer, Float, Double

– Integer a = new Integer(10); – int b = a.intValue();

27/10/2005 Lecture 4: Grouping Objects 35

Fixed-size collections

  • Sometimes the maximum collection size

can be pre-determined.

  • Programming languages usually offer a

special fixed-size collection type: an array.

  • Java arrays can store objects or primitive-

type values.

  • Arrays use a special syntax.
27/10/2005 Lecture 4: Grouping Objects 36

The weblog-analyzer project

  • Web server records details of each access.
  • Supports webmaster’s tasks.

– Most popular pages. – Busiest periods. – How much data is being delivered. – Broken references.

  • Analyze accesses by hour.
slide-26
SLIDE 26

Programming 1 27/10/2005 Lecture 4: Grouping Objects 7

27/10/2005 Lecture 4: Grouping Objects 37

The weblog-analyzer project

27/10/2005 Lecture 4: Grouping Objects 38

Creating an array object

public class LogAnalyzer { private int[] hourCounts; private LogfileReader reader; public LogAnalyzer() { hourCounts = new int[24]; reader = new LogfileReader(); } ... } Array object creation Array variable declaration

27/10/2005 Lecture 4: Grouping Objects 39

The hourCounts array

27/10/2005 Lecture 4: Grouping Objects 40

Using an array

  • Square-bracket notation is used to access an array

element: hourCounts[...]

  • The number of elements of an array can be
  • btained via: hourCounts.length
  • Elements are used like ordinary variables.

– On the left of an assignment:

  • hourCounts[hour] = ...;

– In an expression:

  • adjusted = hourCounts[hour] – 3;
  • hourCounts[hour]++;
  • Arrays are passed by reference while their

elements are passed by value.

27/10/2005 Lecture 4: Grouping Objects 41

The for loop

  • Similar to a while loop.
  • Often used to iterate a fixed number of

times.

  • Often used to iterate over an array.
27/10/2005 Lecture 4: Grouping Objects 42

For loop pseudo-code

for(initialization; condition; post-body action) { statements to be repeated } General form of a for loop Equivalent in while-loop form initialization; while(condition) { statements to be repeated post-body action }

slide-27
SLIDE 27

Programming 1 27/10/2005 Lecture 4: Grouping Objects 8

27/10/2005 Lecture 4: Grouping Objects 43

A Java example

for(int hour = 0; hour < hourCounts.length; hour++) { System.out.println(hour + ": " + hourCounts[hour]); } int hour = 0; while(hour < hourCounts.length) { System.out.println(hour + ": " + hourCounts[hour]); hour++; } for loop version while loop version

27/10/2005 Lecture 4: Grouping Objects 44

Review

  • Arrays are appropriate where a fixed-size

collection is required.

  • Arrays use special syntax.
  • For loops offer an alternative to while loops

when the number of repetitions is known.

  • For loops are often used to iterate over

arrays.

27/10/2005 Lecture 4: Grouping Objects 45

Concepts

  • Java API
  • packages
  • import
  • ArrayList
  • Iterator
  • type cast
  • for
  • while
  • array
  • a++
  • ++a
  • null
slide-28
SLIDE 28

Programming 1 03/11/2005 Lecture 5: More Sophisticated Behavior 1

More sophisticated behavior

Using library classes to implement some more advanced functionality

03/11/2005 Lecture 5: More Sophisticated behavior 2

Main concepts to be covered

  • Using library classes
  • Reading documentation
  • Writing documentation
03/11/2005 Lecture 5: More Sophisticated behavior 3

The Java class library

  • Thousands of classes
  • Tens of thousands of methods
  • Many useful classes that make life much

easier

  • A competent Java programmer must be able

to work with the libraries.

03/11/2005 Lecture 5: More Sophisticated behavior 4

Working with the library

You should:

  • know some important classes by name;
  • know how to find out about other classes.

Remember:

  • We only need to know the interface, not the

implementation.

03/11/2005 Lecture 5: More Sophisticated behavior 5

A Technical Support System

  • A textual dialog system
  • Idea based on ‘Eliza’ by Joseph

Weizenbaum (MIT, 1960s)

  • This is a system that when entering

questions will try to answer them in an “intelligent” way.

03/11/2005 Lecture 5: More Sophisticated behavior 6

A Technical Support System

slide-29
SLIDE 29

Programming 1 03/11/2005 Lecture 5: More Sophisticated Behavior 2

03/11/2005 Lecture 5: More Sophisticated behavior 7

A Technical Support System

03/11/2005 Lecture 5: More Sophisticated behavior 8

Main loop structure

// from the start method in SupportSystem boolean finished = false; while(!finished) {// sentinel controlled loop do something if(exit condition) { finished = true; } else { do something more } }

03/11/2005 Lecture 5: More Sophisticated behavior 9

Main loop body

String input = reader.getInput(); ... String response = responder.generateResponse(); System.out.println(response);

03/11/2005 Lecture 5: More Sophisticated behavior 10

The exit condition

String input = reader.getInput(); if(input.startsWith("bye")) { finished = true; }

  • Where does ‘startsWith’ come from?
  • What is it? What does it do?
  • How can we find out?
03/11/2005 Lecture 5: More Sophisticated behavior 11

String Info

03/11/2005 Lecture 5: More Sophisticated behavior 12

Reading class documentation

  • Documentation of the Java libraries in

HTML format;

  • Readable in a web browser
  • Class API: Application Programmers’

Interface

  • Interface description for all library classes
  • http://java.sun.com/j2se/1.3/docs/api/
slide-30
SLIDE 30

Programming 1 03/11/2005 Lecture 5: More Sophisticated Behavior 3

03/11/2005 Lecture 5: More Sophisticated behavior 13

Interface vs implementation

The documentation includes

  • the name of the class;
  • a general description of the class;
  • a list of constructors and methods
  • return values and parameters for constructors

and methods

  • a description of the purpose of each constructor

and method the interface of the class

03/11/2005 Lecture 5: More Sophisticated behavior 14

Interface vs implementation

The documentation does not include

  • private fields (most fields are private)
  • private methods
  • the bodies (source code) for each method

the implementation of the class

03/11/2005 Lecture 5: More Sophisticated behavior 15

Interface vs implementation

  • The interface of a method consists of

– signature

  • access modifier
  • return type
  • method name
  • a list of parameters

– comment

  • discussion of all signature items
  • purpose of method
03/11/2005 Lecture 5: More Sophisticated behavior 16

Using library classes

  • Classes from the library must be imported

using an import statement (except classes from java.lang).

  • They can then be used like classes from the

current project.

03/11/2005 Lecture 5: More Sophisticated behavior 17

Packages and import

  • Classes are organised in packages.
  • Single classes may be imported:

import java.util.ArrayList;

  • Whole packages can be imported:

import java.util.*;

03/11/2005 Lecture 5: More Sophisticated behavior 18

Side Note 1: Strings

  • Strings are immutable objects

– immutable objects cannot change content or state once they have been created

String input = reader.getInput(); input = input.trim; if(input.startsWith(“bye”)){ finished = true; } else { … Code omitted }

slide-31
SLIDE 31

Programming 1 03/11/2005 Lecture 5: More Sophisticated Behavior 4

03/11/2005 Lecture 5: More Sophisticated behavior 19

Side Note 1: StringBuffer

  • A string buffer implements a mutable

sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.

03/11/2005 Lecture 5: More Sophisticated behavior 20

Side note 2: String equality

if(input == "bye") { tests identity ... } if(input.equals("bye")) { tests equality ... }

  • Strings should (almost) always be compared with .equals
03/11/2005 Lecture 5: More Sophisticated behavior 21

Identity vs equality 1

Other (non-String) objects: person1 == person2 ?

“Fred”

:Person

person1 person2 “Jill”

:Person

03/11/2005 Lecture 5: More Sophisticated behavior 22

Identity vs equality 2

Other (non-String) objects: person1 == person2 ?

“Fred”

:Person

person1 person2 “Fred”

:Person

03/11/2005 Lecture 5: More Sophisticated behavior 23

Identity vs equality 3

Other (non-String) objects: person1 == person2 ?

“Fred”

:Person

person1 person2 “Fred”

:Person

03/11/2005 Lecture 5: More Sophisticated behavior 24

Identity vs equality (Strings)

"bye"

:String

input "bye"

:String String input = reader.getInput(); if(input == "bye") { ... }

== tests identity

== ?

➠ (may be) false!

slide-32
SLIDE 32

Programming 1 03/11/2005 Lecture 5: More Sophisticated Behavior 5

03/11/2005 Lecture 5: More Sophisticated behavior 25

Identity vs equality (Strings)

"bye"

:String

input "bye"

:String String input = reader.getInput(); if(input.equals("bye")) { ... }

equals tests equality

equals

?

➠ true!

03/11/2005 Lecture 5: More Sophisticated behavior 26

Using Random

  • The library class Random can be used to

generate random numbers

import java.util.Random; ... Random randomGenerator = new Random(); ... int index1 = randomGenerator.nextInt(); int index2 = randomGenerator.nextInt(100);

03/11/2005 Lecture 5: More Sophisticated behavior 27

Generating random responses

public Responder() { randomGenerator = new Random(); responses = new ArrayList(); fillResponses(); } public String generateResponse() { int index = randomGenerator.nextInt(responses.size()); return (String) responses.get(index); } public void fillResponses() ... 03/11/2005 Lecture 5: More Sophisticated behavior 28

Maps

  • Maps are collections that contain pairs of

values.

  • Pairs consist of a key and a value.
  • Lookup works by supplying a key, and

retrieving a value.

  • An example: a telephone book.
03/11/2005 Lecture 5: More Sophisticated behavior 29

Using maps

  • A map with Strings as keys and values

"Charles Nguyen"

:HashMap

"(531) 9392 4587" "Lisa Jones" "(402) 4536 4674" "William H. Smith" "(998) 5488 0123"

03/11/2005 Lecture 5: More Sophisticated behavior 30

Using maps

HashMap phoneBook = new HashMap(); phoneBook.put("Charles Nguyen", "(531) 9392 4587"); phoneBook.put("Lisa Jones", "(402) 4536 4674"); phoneBook.put("William H. Smith", "(998) 5488 0123"); String number = (String)phoneBook.get("Lisa Jones"); System.out.println(number);

slide-33
SLIDE 33

Programming 1 03/11/2005 Lecture 5: More Sophisticated Behavior 6

03/11/2005 Lecture 5: More Sophisticated behavior 31

Maps in TechSupport

public class Responder { private HashMap responseMap; … Code Omitted public String generateResponse(String word) { String response = (String) responseMap.get(word); if(response != null) { return response; } else { return pickDefaultResponse(); } } 03/11/2005 Lecture 5: More Sophisticated behavior 32

Using sets

import java.util.HashSet; import java.util.Iterator; ... HashSet mySet = new HashSet(); mySet.add("one"); mySet.add("two"); mySet.add("three"); Iterator it = mySet.iterator(); while(it.hasNext()) { call it.next() to get the next object do something with that object }

Compare this to ArrayList code!

03/11/2005 Lecture 5: More Sophisticated behavior 33

Sets and List

  • A Set is a collection that stores each

individual element at most once. It does not maintain any specific order.

  • A List is a collection that stores all

elements it is been giving regardless of

  • duplication. It maintains a order at all times.
03/11/2005 Lecture 5: More Sophisticated behavior 34

Tokenizing Strings

public HashSet getInput() { System.out.print("> "); String inputLine = readInputLine().trim().toLowerCase(); StringTokenizer tokenizer = new StringTokenizer(inputLine); HashSet words = new HashSet(); while(tokenizer.hasMoreTokens()) { words.add(tokenizer.nextToken()); } return words; }

03/11/2005 Lecture 5: More Sophisticated behavior 35

Writing class documentation

  • Your own classes should be documented the

same way library classes are.

  • Other people should be able to use your

class without reading the implementation.

  • Make your class a 'library class'!
03/11/2005 Lecture 5: More Sophisticated behavior 36

Elements of documentation

Documentation for a class should include:

  • the class name
  • a comment describing the overall purpose

and characteristics of the class

  • a version number
  • the authors’ names
  • documentation for each constructor and

each method

slide-34
SLIDE 34

Programming 1 03/11/2005 Lecture 5: More Sophisticated Behavior 7

03/11/2005 Lecture 5: More Sophisticated behavior 37

javadoc

Class comment:

/** * The Responder class represents a response * generator object. It is used to generate an * automatic response. * * @author Michael Kölling and David J. Barnes * @version 1.0 (1.Feb.2002) */

03/11/2005 Lecture 5: More Sophisticated behavior 38

Elements of documentation

The documentation for each constructor and method should include:

  • the name of the method
  • the return type
  • the parameter names and types
  • a description of the purpose and function of the

method

  • a description of each parameter
  • a description of the value returned
03/11/2005 Lecture 5: More Sophisticated behavior 39

javadoc

Method comment:

/** * Read a line of text from standard input (the text * terminal), and return it as a set of words. * * @param prompt A prompt to print to screen. * @return A set of Strings, where each String is * one of the words typed by the user */ public HashSet getInput(String prompt) { ... }

03/11/2005 Lecture 5: More Sophisticated behavior 40

Public vs private

  • Public attributes (fields, constructors,

methods) are accessible to other classes.

  • Fields should not be public.

– Data encapsulation

  • Private attributes are accessible only within

the same class.

  • Only methods that are intended for other

classes should be public.

03/11/2005 Lecture 5: More Sophisticated behavior 41

Information hiding

  • Data belonging to one object is hidden

from other objects.

  • Know what an object can do, not how it

does it.

  • Information hiding increases the level of

independence.

  • Independence of modules is important for

large systems and maintenance.

03/11/2005 Lecture 5: More Sophisticated behavior 42

The Balls Project

slide-35
SLIDE 35

Programming 1 03/11/2005 Lecture 5: More Sophisticated Behavior 8

03/11/2005 Lecture 5: More Sophisticated behavior 43

Class and Object Level

  • So far we have created classes for the sake
  • f objects which should have each a state of

their own.

  • Sometimes, objects should be able to share

common properties

  • For People this could be the gravitational pull
  • For Employees of the same company this could be

the company’s details

03/11/2005 Lecture 5: More Sophisticated behavior 44

Class and Object Level

  • Instead of having these details stored in each
  • bject it would be better to store this at one central

point:

– THE CLASS

  • Classes themselves can also have state

– class variables or static variables – Exactly one copy exists of a class variable at all times, independent of the number of created instances – The key word static is Java’s syntax to define class variables – methods at object level can access static variables

03/11/2005 Lecture 5: More Sophisticated behavior 45

Class and Object Level

public class BouncingBall { private static final int gravity = 3; // effect of gravity private int ballDegradation = 2; private Ellipse2D.Double circle; private Color color; private int diameter; private int xPosition; private int yPosition; private final int groundPosition; // y position of ground private Canvas canvas; private int ySpeed = 1; 03/11/2005 Lecture 5: More Sophisticated behavior 46

Class variables

03/11/2005 Lecture 5: More Sophisticated behavior 47

Constants

  • Variables can change their value by means of

assignment.

  • Sometimes, when programming you need a

mechanism that can guarantee you that the value does not change at all

  • Constants provide you a way in doing so

– similar to maths or physics

  • pi, i, …

– The key word final is Java’s syntax to express constants – Once given a value, initialized, they can change value – Trying to do so will result in a syntax error.

03/11/2005 Lecture 5: More Sophisticated behavior 48

Constants

private static final int gravity = 3;

  • private: access modifier, as usual
  • static: class variable
  • final: constant
slide-36
SLIDE 36

Programming 1 03/11/2005 Lecture 5: More Sophisticated Behavior 9

03/11/2005 Lecture 5: More Sophisticated behavior 49

Review

  • Java has an extensive class library.
  • A good programmer must be familiar with the

library.

  • The documentation tells us what we need to know

to use a class (interface).

  • The implementation is hidden (information

hiding).

  • We document our classes so that the interface can

be read on its own (class comment, method comments).

03/11/2005 Lecture 5: More Sophisticated behavior 50

Concepts

  • Interface
  • class level
  • static variables
  • class variables
  • object level
  • constants
  • Signature
  • javadoc
  • documentation
  • final
  • static
slide-37
SLIDE 37

Programming 1 10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 1

Well-behaved objects

Improving your coding skills

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 2

Main concepts to be covered

  • Testing
  • Debugging
  • Test automation
  • Writing for maintainability
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 3

We have to deal with errors

  • Early errors are usually syntax errors.

– The compiler will spot these.

  • Later errors are usually logic errors.

– The compiler cannot help with these. – Also known as bugs.

  • Some logical errors have no immediately
  • bvious manifestation.

– Commercial software is rarely error free.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 4

Prevention vs Detection

(Developer vs Maintainer)

  • We can lessen the likelihood of errors.

– Use software engineering techniques, like encapsulation.

  • We can improve the chances of detection.

– Use software engineering practices, like modularization and documentation.

  • We can develop detection skills.
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 5

Testing and debugging

  • These are crucial skills.
  • Testing searches for the presence of errors.
  • Debugging searches for the source of errors.

– The manifestation of an error may well occur some ‘distance’ from its source.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 6

Testing and debugging techniques

  • Unit testing (within BlueJ)
  • Test automation
  • Manual walkthroughs
  • Print statements
  • Debuggers
slide-38
SLIDE 38

Programming 1 10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 2

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 7

Unit testing

  • Each unit of an application may be tested.

– Method, class, module (package in Java).

  • Can (should) be done during development.

– Finding and fixing early lowers development costs (e.g. programmer time). – A test suite is built up.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 8

Testing fundamentals

  • Understand what the unit should do – its

contract.

– You will be looking for violations. – Use positive tests and negative tests.

  • Test boundaries.

– Zero, One, Full.

  • Search an empty collection.
  • Add to a full collection.
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 9

Unit testing within BlueJ

  • Objects of individual classes can be created.
  • Individual methods can be invoked.
  • Inspectors provide an up-to-date view of an
  • bject’s state.
  • Explore through the diary-prototype project.
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 10

Test automation

  • Good testing is a creative process, but ...
  • ... thorough testing is time consuming and

repetitive.

  • Regression testing involves re-running tests.
  • Use of a test rig or test harness can relieve

some of the burden.

– Classes are written to perform the testing. – Creativity focused in creating these.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 11

Test automation

  • Explore through the diary-testing project.

– Human analysis of the results still required.

  • Explore fuller automation through the

diary-test-automation project.

– Intervention only required if a failure is reported.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 12

Modularization and interfaces

  • Applications often consist of different

modules.

– E.g. so that different teams can work on them.

  • The interface between modules must be

clearly specified.

– Supports independent concurrent development. – Increases the likelihood of successful integration.

slide-39
SLIDE 39

Programming 1 10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 3

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 13

Modularization in a calculator

  • Each module does not need to know

implementation details of the other.

– User controls could be a GUI or a hardware device. – Logic could be hardware or software.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 14

Method signatures as an interface

// Return the value to be displayed. public int getDisplayValue(); // Call when a digit button is pressed. public void numberPressed(int number); // Call when a plus operator is pressed. public void plus(); // Call when a minus operator is pressed. public void minus(); // Call to complete a calculation. public void equals(); // Call to reset the calculator. public void clear();

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 15

Debugging

  • It is important to develop code-reading

skills.

– Debugging will often be performed on others’ code.

  • Techniques and tools exist to support the

debugging process.

  • Explore through the calculator-engine

project.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 16

Manual walkthroughs

  • Relatively underused.

– A low-tech approach. – More powerful than appreciated.

  • Get away from the computer!
  • ‘Run’ a program by hand.
  • High-level (Step) or low-level (Step into)

views.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 17

Tabulating object state

  • An object’s behavior is usually determined

by its state.

  • Incorrect behavior is often the result of

incorrect state.

  • Tabulate the values of all fields.
  • Document state changes after each method

call.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 18

Verbal walkthroughs

  • Explain to someone else what the code is

doing.

– They might spot the error. – The process of explaining might help you to spot it for yourself.

  • Group-based processes exist for conducting

formal walkthroughs or inspections.

slide-40
SLIDE 40

Programming 1 10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 4

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 19

Print statements

  • The most popular technique.
  • No special tools required.
  • All programming languages support them.
  • Only effective if the right methods are

documented.

  • Output may be voluminous!
  • Turning off and on requires forethought.
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 20

Debuggers

  • Debuggers are both language- and

environment-specific.

– BlueJ has an integrated debugger.

  • Support breakpoints.
  • Step and Step-into controlled execution.
  • Call sequence (stack).
  • Object state.
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 21

Review

  • Errors are a fact of life in programs.
  • Good software engineering techniques can

reduce their occurrence.

  • Testing and debugging skills are essential.
  • Make testing a habit.
  • Automate testing where possible.
  • Practise a range of debugging skills.

Designing classes

How to write classes in a way that they are easily understandable, maintainable and reusable

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 23

Main concepts to be covered

  • Responsibility-driven design
  • Coupling
  • Cohesion
  • Refactoring
  • Static methods
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 24

Software changes

  • Software is not like a novel that is written
  • nce and then remains unchanged.
  • Software is extended, corrected, maintained,

ported, adapted…

  • The work is done by different people over

time (often decades).

slide-41
SLIDE 41

Programming 1 10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 5

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 25

Change or die

  • There are only two options for software:

– Either it is continuously maintained – or it dies.

  • Software that cannot be maintained will be

thrown away.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 26

World of Zuul

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 27

Code quality

Two important concepts for quality of code:

  • Coupling
  • Cohesion
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 28

Coupling

  • Coupling refers to links between separate

units of a program.

  • If two classes depend closely on many

details of each other, we say they are tightly coupled.

  • We aim for loose coupling.
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 29

Loose coupling

Loose coupling makes it possible to:

  • understand one class without reading others;
  • change one class without affecting others.
  • Thus: improves maintainability.
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 30

Cohesion

  • Cohesion refers to the the number and

diversity of tasks that a single unit is responsible for.

  • If each unit is responsible for one single

logical task, we say it has high cohesion.

  • Cohesion applies to classes and methods.
  • We aim for high cohesion.
slide-42
SLIDE 42

Programming 1 10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 6

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 31

High cohesion

High cohesion makes it easier to:

  • understand what a class or method does;
  • use descriptive names;
  • reuse classes or methods.
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 32

Cohesion of methods

  • A method should be responsible for one and
  • nly one well defined task.
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 33

Cohesion of classes

  • Classes should represent one single, well

defined entity.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 34

Code duplication

Code duplication

  • is an indicator of bad design,
  • makes maintenance harder,
  • can lead to introduction of errors during

maintenance.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 35

Responsibility-driven design

  • Question: where should we add a new

method (which class)?

  • Each class should be responsible for

manipulating its own data.

  • The class that owns the data should be

responsible for processing it.

  • RDD leads to low coupling.
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 36

Localizing change

  • One aim of reducing coupling and

responsibility-driven design is to localize change.

  • When a change is needed, as few classes as

possible should be affected.

slide-43
SLIDE 43

Programming 1 10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 7

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 37

Thinking ahead

  • When designing a class, we try to think

what changes are likely to be made in the future.

  • We aim to make those changes easy.
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 38

Refactoring

  • When classes are maintained, often code is

added.

  • Classes and methods tend to become longer.
  • Every now and then, classes and methods

should be refactored to maintain cohesion and low coupling.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 39

Refactoring and testing

  • When refactoring code, separate the

refactoring from making other changes.

  • First do the refactoring only, without

changing the functionality.

  • Test before and after refactoring to ensure

that nothing was broken.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 40

Design questions

Common questions:

  • How long should a class be?
  • How long should a method be?
  • Can now be answered in terms of cohesion

and coupling.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 41

Design guidelines

  • A method is too long if it does more then
  • ne logical task.
  • A class is too complex if it represents more

than one logical entity.

  • Note: these are guidelines - they still leave

much open to the designer.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 42

Review

  • Programs are continuously changed.
  • It is important to make this change possible.
  • Quality of code requires much more than

just performing correct at one time.

  • Code must be understandable and

maintainable.

slide-44
SLIDE 44

Programming 1 10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 8

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 43

Review

  • Good quality code avoids duplication,

displays high cohesion, low coupling.

  • Coding style (commenting, naming, layout,

etc.) is also important.

  • There is a big difference in the amount of

work required to change poorly structured and well structured code.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 44

Static Methods

  • Previous we discussed class and object

level.

  • We introduced class variables
  • static keyword
  • A similar thing can be done for methods

providing services for the class instead an

  • bject
10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 45

Static Methods (2)

public class StaticTest { static count = 0; public StaticTest { count++; } public static int giveCount() { return count; } … }

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 46

Executing without BlueJ

  • If we want to start a Java application

without BlueJ, we need to use a class method.

  • Java uses a class method with a specific

signature:

– public static void main(String args[]) – args contains the command line options for your application

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 47

Executing without BlueJ (2)

  • Compiling

– javac className.java

  • Running

– java className – java className command line options – but className should contain a main method

  • BlueJ write its own main whenever you ask

it to execute something.

10/11/2005 Lecture 6: Well-behaved Objects and Designing Classes 48

Concepts

  • testing
  • positive and negative

testing

  • debugging
  • unit testing
  • regression testing
  • walkthroughs
  • responsibility-driven

design

  • coupling
  • cohesion
  • refactoring
  • static
  • class methods
  • main method
slide-45
SLIDE 45

Programming 1 17/11/2005 Lecture 7: Inheritance 1

Improving structure with inheritance

17/11/2005 Lecture 7: Inheritance 2

Main concepts to be covered

  • Inheritance
  • Subtyping
  • Substitution
  • Polymorphic variables
17/11/2005 Lecture 7: Inheritance 3

The DoME example

"Database of Multimedia Entertainment"

  • stores details about CDs and videos

– CD: title, artist, # tracks, playing time, got- it, comment – Video: title, director, playing time, got-it, comment

  • allows (later) to search for information or

print lists

17/11/2005 Lecture 7: Inheritance 4

DoME objects

17/11/2005 Lecture 7: Inheritance 5

DoME classes

17/11/2005 Lecture 7: Inheritance 6

DoME object model

slide-46
SLIDE 46

Programming 1 17/11/2005 Lecture 7: Inheritance 2

17/11/2005 Lecture 7: Inheritance 7

Class diagram

17/11/2005 Lecture 7: Inheritance 8

CD source code

public class CD { private String title; private String artist; private String comment; public CD(String theTitle, String theArtist) { title = theTitle; artist = theArtist; comment = " "; } void setComment(String newComment) { ... } String getComment() { ... } void print() { ... } ... }

incomplete (comments!)

[ ]

17/11/2005 Lecture 7: Inheritance 9

Video source code

public class Video { private String title; private String director; private String comment; public Video(String theTitle, String theDirect) { title = theTitle; director = theDirect; comment = " "; } void setComment(String newComment) { ... } String getComment() { ... } void print() { ... } ... }

incomplete (comments!)

[ ]

17/11/2005 Lecture 7: Inheritance 10 class Database { private ArrayList cds; private ArrayList videos; ... public void list() { for(Iterator iter = cds.iterator(); iter.hasNext(); ) { CD cd = (CD)iter.next(); cd.print(); System.out.println(); // empty line between items } for(Iterator iter = videos.iterator(); iter.hasNext(); ) { Video video = (Video)iter.next(); video.print(); System.out.println(); // empty line between items } } }

Database source code

17/11/2005 Lecture 7: Inheritance 11

Critique of DoME

  • code duplication

– CD and Video classes very similar (large part are identical) – makes maintenance difficult/more work – introduces danger of bugs through incorrect maintenance

  • code duplication also in Database class
17/11/2005 Lecture 7: Inheritance 12

Using inheritance

slide-47
SLIDE 47

Programming 1 17/11/2005 Lecture 7: Inheritance 3

17/11/2005 Lecture 7: Inheritance 13

Using inheritance

  • define one superclass : Item
  • define subclasses for Video and CD
  • the superclass defines common attributes
  • the subclasses inherit the superclass

attributes

  • the subclasses add own attributes
17/11/2005 Lecture 7: Inheritance 14

Inheritance hierarchies

17/11/2005 Lecture 7: Inheritance 15

Inheritance in Java

public class Item { ... }

public class CD extends Item { ... } public class Video extends Item { ... }

no change here change here

17/11/2005 Lecture 7: Inheritance 16

Superclass

public class Item { private String title; private int playingTime; private boolean gotIt; private String comment; // constructors and methods omitted. }

17/11/2005 Lecture 7: Inheritance 17

Subclasses

public class CD extends Item { private String artist; private int numberOfTracks; // constructors and methods omitted. } public class Video extends Item { private String director; // constructors and methods omitted. }

17/11/2005 Lecture 7: Inheritance 18

public class Item { private String title; private int playingTime; private boolean gotIt; private String comment; /** * Initialise the fields of the item. */ public Item(String theTitle, int time) { title = theTitle; playingTime = time; gotIt = false; comment = ""; } // methods omitted }

Inheritance and constructors

slide-48
SLIDE 48

Programming 1 17/11/2005 Lecture 7: Inheritance 4

17/11/2005 Lecture 7: Inheritance 19

Inheritance and constructors

public class CD extends Item { private String artist; private int numberOfTracks; /** * Constructor for objects of class CD */ public CD(String theTitle, String theArtist, int tracks, int time) { super(theTitle, time); artist = theArtist; numberOfTracks = tracks; } // methods omitted }

17/11/2005 Lecture 7: Inheritance 20

Superclass constructor call

  • Subclass constructors must always contain

a 'super' call.

  • If none is written, the compiler inserts one

(without parameters)

– works only, if the superclass has a constructor without parameters

  • Must be the first statement in the subclass

constructor.

17/11/2005 Lecture 7: Inheritance 21

Adding more item types

17/11/2005 Lecture 7: Inheritance 22

Deeper hierarchies

17/11/2005 Lecture 7: Inheritance 23

Review (so far)

Inheritance (so far) helps with:

  • Avoiding code duplication
  • Code reuse
  • Easier maintenance
  • Extendibility
17/11/2005 Lecture 7: Inheritance 24

public class Database { private ArrayList items; /** * Construct an empty Database. */ public Database() { items = new ArrayList(); } /** * Add an item to the database. */ public void addItem(Item theItem) { items.add(theItem); } ... }

New Database source code

avoids code duplication in client!

slide-49
SLIDE 49

Programming 1 17/11/2005 Lecture 7: Inheritance 5

17/11/2005 Lecture 7: Inheritance 25

/** * Print a list of all currently stored CDs and * videos to the text terminal. */ public void list() { for(Iterator iter = items.iterator(); iter.hasNext(); ) { Item item = (Item)iter.next(); item.print(); System.out.println(); // empty line between items } }

New Database source code

17/11/2005 Lecture 7: Inheritance 26

Subtyping

First, we had:

public void addCD(CD theCD) public void addVideo(Video theVideo)

Now, we have:

public void addItem(Item theItem)

We call this method with:

Video myVideo = new Video(...); database.addItem(myVideo);

17/11/2005 Lecture 7: Inheritance 27

Subclasses and subtyping

  • Classes define types.
  • Subclasses define subtypes.
  • Objects of subclasses can be used where
  • bjects of supertypes are required.

(This is called substitution .)

17/11/2005 Lecture 7: Inheritance 28

Subtyping and assignment

Vehicle v1 = new Vehicle(); Vehicle v2 = new Car(); Vehicle v3 = new Bicycle();

subclass objects may be assigned to superclass variables

17/11/2005 Lecture 7: Inheritance 29

Subtyping and parameter passing

public class Database { public void addItem(Item theItem) { ... } } Video video = new Video(...); CD cd = new CD(...); database.addItem(video); database.addItem(cd);

subclass objects may be passed to superclass parameters

17/11/2005 Lecture 7: Inheritance 30

Object diagram

slide-50
SLIDE 50

Programming 1 17/11/2005 Lecture 7: Inheritance 6

17/11/2005 Lecture 7: Inheritance 31

Class diagram

17/11/2005 Lecture 7: Inheritance 32

Polymorphic variables

  • Object variables in Java are polymorphic.

(They can hold objects of more than one type.)

  • They can hold objects of the declared type,
  • r of subtypes of the declared type.
17/11/2005 Lecture 7: Inheritance 33

The Object class

All classes inherit from Object.

17/11/2005 Lecture 7: Inheritance 34

Polymorphic collections

  • All collections are polymorphic.
  • The elements are of type Object.

public void add(Object element) public Object get(int index)

17/11/2005 Lecture 7: Inheritance 35

Casting revisited

  • Can assign subtype to supertype.
  • Cannot assign supertype to subtype!

String s1 = myList.get(1); error!

  • Casting fixes this:

String s1 = (String) myList.get(1);

(only if the element really is a String!)

17/11/2005 Lecture 7: Inheritance 36

Wrapper classes

  • All objects can be entered into collections...
  • ...because collections accept elements of

type Object...

  • ...and all classes are subtypes of Object.
  • Great! But what about simple types?
slide-51
SLIDE 51

Programming 1 17/11/2005 Lecture 7: Inheritance 7

17/11/2005 Lecture 7: Inheritance 37

Wrapper classes

  • Simple types (int, char, etc) are not objects. They

must be wrapped into an object!

  • Wrapper classes exist for all simple types:

simple type wrapper class int Integer float Float char Character ... ...

17/11/2005 Lecture 7: Inheritance 38

Wrapper classes

int i = 18; Integer iwrap = new Integer(i); myCollecton.add(iwrap); ... Integer element = (Integer) myCollection.get(0); int value = element.intValue()

wrap the int value add the wrapper retrieve the wrapper unwrap

17/11/2005 Lecture 7: Inheritance 39

Review

  • Inheritance allows the definition of classes as

extensions of other classes.

  • Inheritance

– avoids code duplication – allows code reuse – simplifies the code – simplifies maintenance and extending

  • Variables can hold subtype objects.
  • Subtypes can be used wherever supertype objects

are expected (substitution).

17/11/2005 Lecture 7: Inheritance 40

Concepts

  • Inheritance
  • Superclass
  • Subclass
  • Base Class
  • Object
  • Subtyping
  • Type casting
  • Polymorphic variables
  • Inheritance

Hierarchies

slide-52
SLIDE 52

Programming 1 24/12/2005 Lecture 8: More About Inheritance 1

More about inheritance

Exploring polymorphism

24/11/2005 Lecture 8: More about inheritance 2

Main concepts to be covered

  • method polymorphism
  • static and dynamic type
  • overriding
  • dynamic method lookup
  • protected access
24/11/2005 Lecture 8: More about inheritance 3

The inheritance hierarchy

24/11/2005 Lecture 8: More about inheritance 4

Conflicting output

CD: A Swingin' Affair (64 mins)* Frank Sinatra tracks: 16 my favourite Sinatra album video: The Matrix (136 mins) Andy & Larry Wachowski must see if interested in virtual reality! title: A Swingin' Affair (64 mins)* my favourite Sinatra album title: The Matrix (136 mins) must see if interested in virtual reality!

What we want What we now have

24/11/2005 Lecture 8: More about inheritance 5

The problem

  • The print method in Item only prints the

common fields.

  • Inheritance is a one-way street:

– A subclass inherits the superclass fields. – The superclass knows nothing about its subclass’s fields.

24/11/2005 Lecture 8: More about inheritance 6

Attempting to solve the problem

  • Place print where it has

access to the information it needs.

  • Each subclass has its own

version.

  • But Item’s fields are

private.

  • Database cannot find a

print method in Item.

slide-53
SLIDE 53

Programming 1 24/12/2005 Lecture 8: More About Inheritance 2

24/11/2005 Lecture 8: More about inheritance 7

Static type and dynamic type

  • A more complex type hierarchy requires

further concepts to describe it.

  • Some new terminology:

– static type – dynamic type – method dispatch/lookup

24/11/2005 Lecture 8: More about inheritance 8

Static and dynamic type

Car c1 = new Car();

What is the type of c1?

Vehicle v1 = new Car();

What is the type of v1?

24/11/2005 Lecture 8: More about inheritance 9

Static and dynamic type

  • The declared type of a variable is its static

type.

  • The type of the object a variable refers to is

its dynamic type.

  • The compiler’s job is to check for static-

type violations.

Item item = (Item) iter.next(); item.print(); // Compile-time error.

24/11/2005 Lecture 8: More about inheritance 10

Overriding: the solution

print method in both super- and subclasses. Satisfies both static and dynamic type checking.

24/11/2005 Lecture 8: More about inheritance 11

Overriding

  • Superclass and subclass define methods

with the same signature.

  • Each has access to the fields of its class.
  • Superclass satisfies static type check.
  • Subclass method is called at runtime – it
  • verrides the superclass version.
  • What becomes of the superclass version?
24/11/2005 Lecture 8: More about inheritance 12

Method lookup

No inheritance or polymorphism. The obvious method is selected.

slide-54
SLIDE 54

Programming 1 24/12/2005 Lecture 8: More About Inheritance 3

24/11/2005 Lecture 8: More about inheritance 13

Method lookup

Inheritance but no overriding. The inheritance hierarchy is ascended, searching for a match.

24/11/2005 Lecture 8: More about inheritance 14

Method lookup

Polymorphism and overriding. The ‘first’ version found is used.

24/11/2005 Lecture 8: More about inheritance 15

Method lookup summary

  • The variable is accessed.
  • The object stored in the variable is found.
  • The class of the object is found.
  • The class is searched for a method match.
  • If no match is found, the superclass is searched.
  • This is repeated until a match is found, or the class

hierarchy is exhausted.

  • Overriding methods take precedence.
24/11/2005 Lecture 8: More about inheritance 16

Super call in methods

  • Overridden methods are hidden ...
  • ... but we often still want to be able to call

them.

  • An overridden method can be called from

the method that overrides it.

– super.method(...) – Compare with the use of super in constructors.

24/11/2005 Lecture 8: More about inheritance 17

Calling an overridden method

public class CD { ... public void print() { super.print(); System.out.println(" " + artist); System.out.println(" tracks: " + numberOfTracks); } ... }

24/11/2005 Lecture 8: More about inheritance 18

Method polymorphism

  • We have been discussing polymorphic

method dispatch.

  • A polymorphic variable can store objects of

varying types.

  • Method calls are polymorphic.

– The actual method called depends on the dynamic object type.

slide-55
SLIDE 55

Programming 1 24/12/2005 Lecture 8: More About Inheritance 4

24/11/2005 Lecture 8: More about inheritance 19

The Object class’s methods

  • Methods in Object are inherited by all

classes.

  • Any of these may be overridden.
  • The toString method is commonly
  • verridden:

– public String toString() – Returns a string representation of the object.

24/11/2005 Lecture 8: More about inheritance 20

Overriding toString

public class Item { ... public String toString() { String line1 = title + " (" + playingTime + " mins)"); if(gotIt) { return line1 + "*\n" + " " + comment + "\n"); } else { return line1 + "\n" + " " + comment + "\n"); } } ... }

24/11/2005 Lecture 8: More about inheritance 21

Overriding toString

  • Explicit print methods can often be
  • mitted from a class:

– System.out.println(item.toString());

  • Calls to println with just an object

automatically result in toString being called:

– System.out.println(item);

24/11/2005 Lecture 8: More about inheritance 22

Protected access

  • Private access in the superclass may be too

restrictive for a subclass.

  • The closer inheritance relationship is

supported by protected access.

  • Protected access is more restricted than

public access.

  • We still recommend keeping fields private.

– Define protected accessors and mutators.

24/11/2005 Lecture 8: More about inheritance 23

Access levels

24/11/2005 Lecture 8: More about inheritance 24

Review

  • The declared type of a variable is its static type.

– Compilers check static types.

  • The type of an object is its dynamic type.

– Dynamic types are used at runtime.

  • Methods may be overridden in a subclass.
  • Method lookup starts with the dynamic type.
  • Protected access supports inheritance.
slide-56
SLIDE 56

Programming 1 24/12/2005 Lecture 8: More About Inheritance 5

24/11/2005 Lecture 8: More about inheritance 25

Concepts

  • method polymorphism
  • overriding
  • dynamic method

lookup

  • static types
  • dynamic types
  • super
  • protected
24/11/2005 Lecture 8: More about inheritance 26

Class Exercise

  • Design a Local Area Network application. This

application consists of the following classes:

  • Node, Workstation, Fileserver and Printserver, and

Packet.

  • A Packet is an object transporting textual

information to a given LAN-element.

  • A Workstation is a special Node in the sense that

it is the only one which can put Packets on the LAN.

24/11/2005 Lecture 8: More about inheritance 27

Class Exercise (II)

  • A Fileserver saves the contents of the Packets to a

file (which is created with the same name as the Fileserver with a .txt extension). The contents of the Packets should be put in file separated by '@'.

  • A Printserver prints the contents of the Packet to

standard output.

  • The LAN we are simulating is circular such that

Packets cannot drop off the LAN. This means that each LAN-element should keep a link to the next LAN-element.

24/11/2005 Lecture 8: More about inheritance 28

Class Exercise (III)

  • Any LAN-element should be able to stop a Packet.

Of course this can only be done if the Packet is addressed to it. Make sure that a Packet does not circle indefinitely.

  • Design each of the classes: specify static and

instance fields and methods. Describe the purpose

  • f all of those. If required, specify the inheritance

relationship between them. Were do you use polymorphism (if ever)?

slide-57
SLIDE 57

Programming 1 01/12/2005 Lecture 9: Abstraction Techniques 1

Further abstraction techniques

Abstract classes and interfaces

1.0 01/12/2005 Lecture 9: Abstraction Techniques 2

Main concepts to be covered

  • Abstract classes
  • Interfaces
  • Multiple inheritance
01/12/2005 Lecture 9: Abstraction Techniques 3

Simulations

  • Programs regularly used to simulate real-world

activities.

– city traffic – the weather – nuclear processes – stock market fluctuations – environmental changes – LAN networks – animal behavior

01/12/2005 Lecture 9: Abstraction Techniques 4

Simulations

  • They are often only partial simulations.
  • They often involve simplifications.

– Greater detail has the potential to provide greater accuracy. – Greater detail typically requires more resources.

  • Processing power.
  • Simulation time.
01/12/2005 Lecture 9: Abstraction Techniques 5

Benefits of simulations

  • Support useful prediction.

– The weather.

  • Allow experimentation.

– Safer, cheaper, quicker.

  • Example:

– ‘How will the wildlife be affected if we cut a highway through the middle of this national park?’

01/12/2005 Lecture 9: Abstraction Techniques 6

Predator-prey simulations

  • There is often a delicate balance between

species.

– A lot of prey means a lot of food. – A lot of food encourages higher predator numbers. – More predators eat more prey. – Less prey means less food. – Less food means ...

slide-58
SLIDE 58

Programming 1 01/12/2005 Lecture 9: Abstraction Techniques 2

01/12/2005 Lecture 9: Abstraction Techniques 7

The foxes-and-rabbits project

01/12/2005 Lecture 9: Abstraction Techniques 8

Main classes of interest

  • Fox

– Simple model of a type of predator.

  • Rabbit

– Simple model of a type of prey.

  • Simulator

– Manages the overall simulation task. – Holds a collection of foxes and rabbits.

01/12/2005 Lecture 9: Abstraction Techniques 9

The remaining classes

  • Field

– Represents a 2D field.

  • Location

– Represents a 2D position.

  • SimulatorView, FieldStats,

Counter

– Maintain statistics and present a view

  • f the field.
01/12/2005 Lecture 9: Abstraction Techniques 10

Example of the visualization

01/12/2005 Lecture 9: Abstraction Techniques 11

A Rabbit’s state

// Characteristics shared by all rabbits (static fields). // The age at which a rabbit can start to breed. private static final int BREEDING_AGE = 5; // The age to which a rabbit can live. private static final int MAX_AGE = 50; // The likelihood of a rabbit breeding. private static final double BREEDING_PROBABILITY = 0.15; // The maximum number of births. private static final int MAX_LITTER_SIZE = 5; // A shared random number generator to control breeding. private static final Random rand = new Random(); 01/12/2005 Lecture 9: Abstraction Techniques 12

A Rabbit’s state

// Individual characteristics (instance fields). // The rabbit's age. private int age; // Whether the rabbit is alive or not. private boolean alive; // The rabbit's position private Location location;

slide-59
SLIDE 59

Programming 1 01/12/2005 Lecture 9: Abstraction Techniques 3

01/12/2005 Lecture 9: Abstraction Techniques 13

A Rabbit’s behavior

  • Managed from the run method.
  • Age incremented at each simulation ‘step’.

– A rabbit could die at this point.

  • Rabbits that are old enough might breed at

each step.

– New rabbits could be born at this point.

01/12/2005 Lecture 9: Abstraction Techniques 14

A Rabbit’s behavior

public Rabbit(boolean randomAge){…} public void run(Field updatedField, List newRabbits) { incrementAge(); if(alive) { int births = breed(); for(int b = 0; b < births; b++) { Rabbit newRabbit = new Rabbit(false); newRabbits.add(newRabbit); Location loc = updatedField.randomAdjacentLocation(location); newRabbit.setLocation(loc); updatedField.place(newRabbit, loc); }

01/12/2005 Lecture 9: Abstraction Techniques 15

A Rabbit’s behavior

Location newLocation = updatedField.freeAdjacentLocation(location); // Only transfer to the updated field if //there was a free location if(newLocation != null) { setLocation(newLocation); updatedField.place(this, newLocation); } else { // can neither move nor stay – //overcrowding - all locations taken alive = false; }}}

01/12/2005 Lecture 9: Abstraction Techniques 16

A Rabbit’s behavior

private void incrementAge() { age++; if(age > MAX_AGE) { alive = false; } } private int breed() { int births = 0; if(canBreed() && rand.nextDouble() <= BREEDING_PROBABILITY) { births = rand.nextInt(MAX_LITTER_SIZE) + 1; } return births; } 01/12/2005 Lecture 9: Abstraction Techniques 17

Rabbit simplifications

  • Rabbits do not have different genders.

– In effect, all are female.

  • The same rabbit could breed at every step.
  • All rabbits die at the same age.
01/12/2005 Lecture 9: Abstraction Techniques 18

A Fox’s state

public class Fox { Static fields omitted // The fox's age. private int age; // Whether the fox is alive or not. private boolean alive; // The fox's position private Location location; // The fox's food level, which is increased // by eating rabbits. private int foodLevel; Methods omitted. }

slide-60
SLIDE 60

Programming 1 01/12/2005 Lecture 9: Abstraction Techniques 4

01/12/2005 Lecture 9: Abstraction Techniques 19

A Fox’s behavior

  • Managed from the hunt method.
  • Foxes also age and breed.
  • They become hungry.
  • They hunt for food in adjacent locations.
01/12/2005 Lecture 9: Abstraction Techniques 20

A Fox’s behavior

public void hunt(Field currentField, Field updatedField, List newFoxes) { incrementAge(); incrementHunger(); if(isAlive()) { // New foxes are born into adjacent locations. int births = breed(); for(int b = 0; b < births; b++) { Fox newFox = new Fox(false); newFoxes.add(newFox); Location loc = updatedField.randomAdjacentLocation(location); newFox.setLocation(loc); updatedField.place(newFox, loc); }

01/12/2005 Lecture 9: Abstraction Techniques 21

A Fox’s behavior

// Move towards the source of food if found. Location newLocation = findFood(currentField, location); if(newLocation == null) {// no food found –move randomly newLocation = updatedField.freeAdjacentLocation(location); } if(newLocation != null) { setLocation(newLocation); updatedField.place(this, newLocation); } else { // can neither move nor stay - overcrowding – all // locations taken alive = false; }}} 01/12/2005 Lecture 9: Abstraction Techniques 22

A Fox’s behavior

private Location findFood(Field field, Location location) { Iterator adjacentLocations = field.adjacentLocations(location); while(adjacentLocations.hasNext()) { Location where = (Location) adjacentLocations.next(); Object animal = field.getObjectAt(where); if(animal instanceof Rabbit) { Rabbit rabbit = (Rabbit) animal; if(rabbit.isAlive()) { rabbit.setEaten(); foodLevel = RABBIT_FOOD_VALUE; return where; }}} return null; }

01/12/2005 Lecture 9: Abstraction Techniques 23

Configuration of foxes

  • Similar simplifications to rabbits.
  • Hunting and eating could be modeled in

many different ways.

– Should food level be additive? – Is a hungry fox more or less likely to hunt?

  • Are simplifications ever acceptable?
01/12/2005 Lecture 9: Abstraction Techniques 24

The Simulator class

  • Three key components:

– Setup in the constructor. – The populate method.

  • Each animal is given a random starting age.

– The simulateOneStep method.

  • Iterates over the population.
  • Two Field objects are used: field and

updatedField.

slide-61
SLIDE 61

Programming 1 01/12/2005 Lecture 9: Abstraction Techniques 5

01/12/2005 Lecture 9: Abstraction Techniques 25

The update step

public class Simulator { … public void simulateOneStep() { step++; newAnimals.clear(); // let all animals act for(Iterator iter = animals.iterator(); iter.hasNext(); ) { Object animal = iter.next();

01/12/2005 Lecture 9: Abstraction Techniques 26

The update step

if(animal instanceof Rabbit) { Rabbit rabbit = (Rabbit)animal; if(rabbit.isAlive()) { rabbit.run(updatedField, newAnimals); } else { iter.remove(); } } else if(animal instanceof Fox) { Fox fox = (Fox)animal; if(fox.isAlive()) { fox.hunt(field, updatedField, newAnimals); } else { iter.remove(); } }

01/12/2005 Lecture 9: Abstraction Techniques 27

Instanceof

  • Checking an object’s dynamic type

– obj instanceof Myclass

  • General not considered good practice
  • Make code to depend on the exact type of
  • bjects.
  • The usage of instanceof is an indicator of

refactoring

01/12/2005 Lecture 9: Abstraction Techniques 28

Room for improvement

  • Fox and Rabbit have strong similarities

but do not have a common superclass.

  • The Simulator is tightly coupled to the

specific classes.

– It ‘knows’ a lot about the behavior of foxes and rabbits.

01/12/2005 Lecture 9: Abstraction Techniques 29

The Animal superclass

  • Place common fields in Animal:

– age, alive, location

  • Method renaming to support

information hiding:

– run and hunt become act.

  • Simulator can now be significantly

decoupled.

01/12/2005 Lecture 9: Abstraction Techniques 30

Revised (decoupled) iteration

for(Iterator iter = animals.iterator(); iter.hasNext(); ) { Animal animal = (Animal)iter.next(); if(animal.isAlive()) { animal.act(field, updatedField, newAnimals); } else { iter.remove(); } }

slide-62
SLIDE 62

Programming 1 01/12/2005 Lecture 9: Abstraction Techniques 6

01/12/2005 Lecture 9: Abstraction Techniques 31

The act method of Animal

  • Static type checking requires an act

method in Animal.

  • There is no obvious shared implementation.
  • Define act as abstract:

abstract public void act(Field currentField, Field updatedField, List newAnimals);

01/12/2005 Lecture 9: Abstraction Techniques 32

Abstract classes and methods

  • Abstract methods have abstract in the

signature.

  • Abstract methods have no body.
  • Abstract methods make the class abstract.
  • Abstract classes cannot be instantiated.
  • Concrete subclasses complete the

implementation.

01/12/2005 Lecture 9: Abstraction Techniques 33

The Animal class

public abstract class Animal { fields omitted /** * Make this animal act - that is: make it do * whatever it wants/needs to do. */ abstract public void act(Field currentField, Field updatedField, List newAnimals);

  • ther methods omitted

}

01/12/2005 Lecture 9: Abstraction Techniques 34

More abstract methods

public boolean canBreed() { return age >= getbreedingAge() } abstract public int getBreedingAge();

  • Note: fields are handled differently from methods in Java:

they cannot be overridden by subclass version

– both Rabbit and Fox have their own static field BREEDING_AGE and Animal has none.

01/12/2005 Lecture 9: Abstraction Techniques 35

Further abstraction

01/12/2005 Lecture 9: Abstraction Techniques 36

Selective drawing (multiple inheritance)

// let all animals act for(Iterator iter = actors.iterator(); iter.hasNext();) { Actor actor = (Actor) iter.next(); actor.act(…); } for(Iterator iter = drawables.iterator(); iter.hasNext();) { Drawable item = (Drawable) iter.hasNext(); item.draw(…); }

slide-63
SLIDE 63

Programming 1 01/12/2005 Lecture 9: Abstraction Techniques 7

01/12/2005 Lecture 9: Abstraction Techniques 37

Selective drawing (multiple inheritance)

01/12/2005 Lecture 9: Abstraction Techniques 38

Multiple inheritance

  • Having a class inherit directly from multiple

ancestors.

  • Each language has its own rules.

– How to resolve competing definitions?

  • Java forbids it for classes.
  • Java permits it for interfaces.

– No competing implementation.

01/12/2005 Lecture 9: Abstraction Techniques 39

An Actor interface

public interface Actor { /** * Perform the actor's daily behavior. * Transfer the actor to updatedField if it is * to participate in further steps of the simulation. * @param currentField The current state of the field. * @param location The actor's location in the field. * @param updatedField The updated state of the field. */ void act(Field currentField, Location location, Field updatedField); }

01/12/2005 Lecture 9: Abstraction Techniques 40

Interfaces

  • A Java interface is a specification of a type (in the

form of a type name and methods) that does not define any implementation of methods

  • uses interface instead of class
  • all methods are public (no need to mention)
  • all methods are abstract (no need to mention)
  • no constructors
  • all constant fields are allowed (public static final)
01/12/2005 Lecture 9: Abstraction Techniques 41

Classes implement an interface

public class Fox extends Animal implements Drawable { ... } public class Hunter implements Actor, Drawable { ... }

01/12/2005 Lecture 9: Abstraction Techniques 42

Interfaces as types

  • Implementing classes do not inherit code,

but ...

  • ... implementing classes are subtypes of the

interface type.

  • So, polymorphism is available with

interfaces as well as classes.

slide-64
SLIDE 64

Programming 1 01/12/2005 Lecture 9: Abstraction Techniques 8

01/12/2005 Lecture 9: Abstraction Techniques 43

Interfaces as specifications

  • Strong separation of functionality from

implementation.

– Though parameter and return types are mandated.

  • Clients interact independently of the

implementation.

– But clients can choose from alternative implementations.

01/12/2005 Lecture 9: Abstraction Techniques 44

Alternative implementations

01/12/2005 Lecture 9: Abstraction Techniques 45

Review

  • Inheritance can provide shared

implementation.

– Concrete and abstract classes.

  • Inheritance provides shared type

information.

– Classes and interfaces.

01/12/2005 Lecture 9: Abstraction Techniques 46

Review

  • Abstract methods allow static type checking

without requiring implementation.

  • Abstract classes function as incomplete

superclasses.

– No instances.

  • Abstract classes support polymorphism.
01/12/2005 Lecture 9: Abstraction Techniques 47

Interfaces

  • Interfaces provide specification without

implementation.

– Interfaces are fully abstract.

  • Interfaces support polymorphism.
  • Java interfaces support multiple inheritance.
01/12/2005 Lecture 9: Abstraction Techniques 48

Concepts

  • abstract class
  • interfaces
  • instanceof
slide-65
SLIDE 65

Programming 1 08/12/2005 Lecture 10: Handling Errors 1

Handling errors

Writing robust code

08/12/2005 Lecture 10: Handling Errors 2

Main concepts to be covered

  • Defensive programming.

– Anticipating that things could go wrong.

  • Exception handling and throwing.
  • Error reporting.
  • Simple file processing.
08/12/2005 Lecture 10: Handling Errors 3

Some causes of error situations

  • Incorrect implementation.

– Does not meet the specification.

  • Inappropriate object request.

– E.g., invalid index.

  • Inconsistent or inappropriate object state.

– E.g. arising through class extension.

08/12/2005 Lecture 10: Handling Errors 4

Not always programmer error

  • Errors often arise from the environment:

– Incorrect URL entered. – Network interruption.

  • File processing is particular error-prone:

– Missing files. – Lack of appropriate permissions.

08/12/2005 Lecture 10: Handling Errors 5

Exploring errors

  • Explore error situations through the

address-book projects.

  • Two aspects:

– Error reporting. – Error handling.

08/12/2005 Lecture 10: Handling Errors 6

Defensive programming

  • Client-server interaction.

– Should a server assume that clients are well- behaved? – Or should it assume that clients are potentially hostile?

  • Significant differences in implementation

required.

slide-66
SLIDE 66

Programming 1 08/12/2005 Lecture 10: Handling Errors 2

08/12/2005 Lecture 10: Handling Errors 7

Issues to be addressed

  • How much checking by a server on method

calls?

  • How to report errors?
  • How can a client anticipate failure?
  • How should a client deal with failure?
08/12/2005 Lecture 10: Handling Errors 8

An example

  • Create an AddressBook object.
  • Try to remove an entry.
  • A runtime error results.

– Whose ‘fault’ is this?

  • Anticipation and prevention are preferable

to apportioning blame.

08/12/2005 Lecture 10: Handling Errors 9

Argument values

  • Arguments represent a major ‘vulnerability’

for a server object.

– Constructor arguments initialize state. – Method arguments often contribute to behavior.

  • Argument checking is one defensive

measure.

08/12/2005 Lecture 10: Handling Errors 10

Checking the key

public void removeDetails(String key) { if(keyInUse(key)) { ContactDetails details = (ContactDetails) book.get(key); book.remove(details.getName()); book.remove(details.getPhone()); numberOfEntries--; } }

08/12/2005 Lecture 10: Handling Errors 11

Server error reporting

  • How to report illegal arguments?

– To the user?

  • Is there a human user?
  • Can they solve the problem?

– To the client object?

  • Return a diagnostic value.
  • Throw an exception.
08/12/2005 Lecture 10: Handling Errors 12

Returning a diagnostic

public boolean removeDetails(String key) { if(keyInUse(key)) { ContactDetails details = (ContactDetails) book.get(key); book.remove(details.getName()); book.remove(details.getPhone()); numberOfEntries--; return true; } else { return false; } }

slide-67
SLIDE 67

Programming 1 08/12/2005 Lecture 10: Handling Errors 3

08/12/2005 Lecture 10: Handling Errors 13

Client responses

  • Test the return value.

– Attempt recovery on error. – Avoid program failure.

  • Ignore the return value.

– Cannot be prevented. – Likely to lead to program failure.

  • Exceptions are preferable.
08/12/2005 Lecture 10: Handling Errors 14

Exception-throwing principles

  • A special language feature.
  • No ‘special’ return value needed.
  • Errors cannot be ignored in the client.

– The normal flow-of-control is interrupted.

  • Specific recovery actions are encouraged.
08/12/2005 Lecture 10: Handling Errors 15

Throwing an exception

/** * Look up a name or phone number and return the * corresponding contact details. * @param key The name or number to be looked up. * @return The details corresponding to the key, * or null if there are none matching. * @throws NullPointerException if the key is null. */ public ContactDetails getDetails(String key) { if(key == null){ throw new NullPointerException( "null key in getDetails"); } return (ContactDetails) book.get(key); }

08/12/2005 Lecture 10: Handling Errors 16

Throwing an exception

  • An exception object is constructed:

– new ExceptionType("...");

  • The exception object is thrown:

– throw ...

  • Javadoc documentation:

– @throws ExceptionType reason

08/12/2005 Lecture 10: Handling Errors 17

The exception class hierarchy

08/12/2005 Lecture 10: Handling Errors 18

Exception categories

  • Checked exceptions

– Subclass of Exception – Use for anticipated failures. – Where recovery may be possible.

  • Unchecked exceptions

– Subclass of RuntimeException – Use for unanticipated failures. – Where recovery is unlikely.

slide-68
SLIDE 68

Programming 1 08/12/2005 Lecture 10: Handling Errors 4

08/12/2005 Lecture 10: Handling Errors 19

The effect of an exception

  • The throwing method finishes prematurely.
  • No return value is returned.
  • Control does not return to the client’s point
  • f call.

– So the client cannot carry on regardless.

  • A client may ‘catch’ an exception.
08/12/2005 Lecture 10: Handling Errors 20

Unchecked exceptions

  • Use of these is ‘unchecked’ by the

compiler.

  • Cause program termination if not caught.

– This is the normal practice.

  • IllegalArgumentException is a

typical example.

08/12/2005 Lecture 10: Handling Errors 21

Argument checking

public ContactDetails getDetails(String key) { if(key == null) { throw new NullPointerException( "null key in getDetails"); } if(key.trim().length() == 0) { throw new IllegalArgumentException( "Empty key passed to getDetails"); } return (ContactDetails) book.get(key); }

08/12/2005 Lecture 10: Handling Errors 22

Preventing object creation

public ContactDetails(String name, String phone, String address) { if(name == null) { name = ""; } if(phone == null) { phone = ""; } if(address == null) { address = ""; } this.name = name.trim(); this.phone = phone.trim(); this.address = address.trim(); if(this.name.length() == 0 && this.phone.length() == 0) { throw new IllegalStateException( "Either the name or phone must not be blank."); } } 08/12/2005 Lecture 10: Handling Errors 23

Exception handling

  • Checked exceptions are meant to be caught.
  • The compiler ensures that their use is tightly

controlled.

– In both server and client.

  • Used properly, failures may be recoverable.
08/12/2005 Lecture 10: Handling Errors 24

The throws clause

  • Methods throwing a checked exception

must include a throws clause:

public void saveToFile(String destinationFile) throws IOException

slide-69
SLIDE 69

Programming 1 08/12/2005 Lecture 10: Handling Errors 5

08/12/2005 Lecture 10: Handling Errors 25

The try block

  • Clients catching an exception must protect

the call with a try block:

try { Protect one or more statements here. } catch(Exception e) { Report and recover from the exception here. }

08/12/2005 Lecture 10: Handling Errors 26

The try block

try{ addressbook.saveToFile(filename); tryAgain = false; } catch(IOException e) { System.out.println("Unable to save to " + filename); tryAgain = true; }

  • 1. Exception thrown from here
  • 2. Control transfers to here
08/12/2005 Lecture 10: Handling Errors 27

Catching multiple exceptions

try { ... ref.process(); ... } catch(EOFException e) { // Take action on an end-of-file exception. ... } catch(FileNotFoundException e) { // Take action on a file-not-found exception. ... }

08/12/2005 Lecture 10: Handling Errors 28

The finally clause

try { Protect one or more statements here. } catch(Exception e) { Report and recover from the exception here. } finally { Perform any actions here common to whether or not an exception is thrown. }

08/12/2005 Lecture 10: Handling Errors 29

The finally clause

  • A finally clause is executed even if a return

statement is executed in the try or catch clauses.

  • A uncaught or propagated exception still

exits via the finally clause.

08/12/2005 Lecture 10: Handling Errors 30

Defining new exceptions

  • Extend Exception or Runtime-

Exception.

  • Define new types to give better diagnostic

information.

– Include reporting and/or recovery information.

slide-70
SLIDE 70

Programming 1 08/12/2005 Lecture 10: Handling Errors 6

08/12/2005 Lecture 10: Handling Errors 31

public class NoMatchingDetailsException extends Exception { private String key; public NoMatchingDetailsException(String key) { this.key = key; } public String getKey() { return key; } public String toString() { return "No details matching '" + key + "' were found."; } }

08/12/2005 Lecture 10: Handling Errors 32

Error recovery

  • Clients should take note of error

notifications.

– Check return values. – Don’t ‘ignore’ exceptions.

  • Include code to attempt recovery.

– Will often require a loop.

08/12/2005 Lecture 10: Handling Errors 33

Attempting recovery

// Try to save the address book. boolean successful = false; int attempts = 0; do { try { addressbook.saveToFile(filename); successful = true; } catch(IOException e) { System.out.println("Unable to save to " + filename); attempts++; if(attempts < MAX_ATTEMPTS) { filename = an alternative file name; } } } while(!successful && attempts < MAX_ATTEMPTS); if(!successful) { Report the problem and give up; } 08/12/2005 Lecture 10: Handling Errors 34

Error avoidance

  • Clients can often use server query methods

to avoid errors.

– More robust clients mean servers can be more trusting. – Unchecked exceptions can be used. – Simplifies client logic.

  • May increase client-server coupling.
08/12/2005 Lecture 10: Handling Errors 35

Text input-output

  • Input-output is particularly error-prone.

– It involves interaction with the external environment.

  • The java.io package supports input-
  • utput.
  • java.io.IOException is a checked

exception.

08/12/2005 Lecture 10: Handling Errors 36

Readers, writers, streams

  • Readers and writers deal with textual input.

– Based around the char type.

  • Streams deal with binary data.

– Based around the byte type.

  • The address-book-io project illustrates

textual IO.

slide-71
SLIDE 71

Programming 1 08/12/2005 Lecture 10: Handling Errors 7

08/12/2005 Lecture 10: Handling Errors 37

Text output

  • Use the FileWriter class.

– Open a file. – Write to the file. – Close the file.

  • Failure at any point results in an

IOException.

08/12/2005 Lecture 10: Handling Errors 38

Text output

try { FileWriter writer = new FileWriter("name of file"); while(there is more text to write) { ... writer.write(next piece of text); ... } writer.close(); } catch(IOException e) { something went wrong with accessing the file }

08/12/2005 Lecture 10: Handling Errors 39

Text input

  • Use the FileReader class.
  • Augment with BufferedReader for

line-based input.

– Open a file. – Read from the file. – Close the file.

  • Failure at any point results in an

IOException.

08/12/2005 Lecture 10: Handling Errors 40

Text input

try { BufferedReader reader = new BufferedReader( new FileReader("name of file ")); String line = reader.readLine(); while(line != null) { do something with line line = reader.readLine(); } reader.close(); } catch(FileNotFoundException e) { the specified file could not be found } catch(IOException e) { something went wrong with reading or closing } 08/12/2005 Lecture 10: Handling Errors 41

Review

  • Runtime errors arise for many reasons.

– An inappropriate client call to a server object. – A server unable to fulfill a request. – Programming error in client and/or server.

08/12/2005 Lecture 10: Handling Errors 42

Review

  • Runtime errors often lead to program

failure.

  • Defensive programming anticipates errors –

in both client and server.

  • Exceptions provide a reporting and recovery

mechanism.

slide-72
SLIDE 72

Programming 1 08/12/2005 Lecture 10: Handling Errors 8

08/12/2005 Lecture 10: Handling Errors 43

Concepts

  • try
  • catch
  • throw
  • finally
  • Defensive

programming

  • Exception
  • Error
  • Reader
  • Writer
  • Streams
slide-73
SLIDE 73

Programming 1 15/12/2005 Lecture 11: Designing Applications 1

Designing applications

Software Engineering from a Code Perspective

15/12/2005 Lecture 11: Designing Applications 2

Main concepts to be covered

  • Discovering classes
  • CRC cards
  • Designing interfaces
  • Patterns
15/12/2005 Lecture 11: Designing Applications 3

Analysis and design

  • A large and complex area.
  • The verb/noun method is suitable for

relatively small problems.

  • CRC cards support the design process.
15/12/2005 Lecture 11: Designing Applications 4

The verb/noun method

  • The nouns in a description refer to ‘things’.

– A source of classes and objects.

  • The verbs refer to actions.

– A source of interactions between objects. – Actions are behavior, and hence methods.

15/12/2005 Lecture 11: Designing Applications 5

A problem description

The cinema booking system should store seat bookings for multiple theatres. Each theatre has seats arranged in rows. Customers can reserve seats and are given a row number and seat number. They may request bookings of several adjoining seats. Each booking is for a particular show (i.e., the screening of a given movie at a certain time). Shows are at an assigned date and time, and scheduled in a theatre where they are screened. The system stores the customers’ telephone number.

15/12/2005 Lecture 11: Designing Applications 6

Nouns and verbs

Cinema booking system Stores (seat bookings) Stores (telephone number) Seat booking Theatre Has (seats) Seat Row Customer Reserves (seats) Is given (row number, seat number) Requests (seat booking) Row number Seat number Show Is scheduled (in theatre) Movie Date Time Telephone number

slide-74
SLIDE 74

Programming 1 15/12/2005 Lecture 11: Designing Applications 2

15/12/2005 Lecture 11: Designing Applications 7

Using CRC cards

  • First described by Kent Beck and Ward

Cunningham.

  • Each index cards records:

– A class name. – The class’s responsibilities. – The class’s collaborators.

15/12/2005 Lecture 11: Designing Applications 8

A CRC card

Class name Collaborators Responsibilities

15/12/2005 Lecture 11: Designing Applications 9

A partial example

CinemaBookingSystem Collaborators Can find shows by Show title and day. Stores collection of Collection shows. Retrieves and displays show details. ...

15/12/2005 Lecture 11: Designing Applications 10

Scenarios

  • An activity that the system has to carry out
  • r support.

– Sometimes known as use cases.

  • Used to discover and record object

interactions (collaborations).

  • Can be performed as a group activity.
15/12/2005 Lecture 11: Designing Applications 11

Scenarios as analysis

  • Scenarios serve to check the problem

description is clear and complete.

  • Sufficient time should be taken over the

analysis.

  • The analysis will lead into design.

– Spotting errors or omissions here will save considerable wasted effort later.

15/12/2005 Lecture 11: Designing Applications 12

Class design

  • Scenario analysis helps to clarify

application structure.

– Each card maps to a class. – Collaborations reveal class cooperation/object interaction.

  • Responsibilities reveal public methods.

– And sometimes fields; e.g. “Stores collection ...”

slide-75
SLIDE 75

Programming 1 15/12/2005 Lecture 11: Designing Applications 3

15/12/2005 Lecture 11: Designing Applications 13

Designing class interfaces

  • Replay the scenarios in terms of method

calls, parameters and return values.

  • Note down the resulting signatures.
  • Create outline classes with public-method

stubs.

  • Careful design is a key to successful

implementation.

15/12/2005 Lecture 11: Designing Applications 14

Documentation

  • Write class comments.
  • Write method comments.
  • Describe the overall purpose of each.
  • Documenting now ensures that:

– The focus is on what rather than how. – That it doesn’t get forgotten!

15/12/2005 Lecture 11: Designing Applications 15

Cooperation

  • Team-working is likely to be the norm not

the exception.

  • Documentation is essential for team

working.

  • Clean O-O design, with loosely-coupled

components, also supports cooperation.

15/12/2005 Lecture 11: Designing Applications 16

Prototyping

  • Supports early investigation of a system.

– Early problem identification.

  • Incomplete components can be simulated.

– E.g. always returning a fixed result. – Avoid random behavior which is difficult to reproduce.

15/12/2005 Lecture 11: Designing Applications 17

Software growth

  • Waterfall model.

– Analysis – Design – Implementation – Unit testing – Integration testing – Delivery

  • No provision for iteration.
15/12/2005 Lecture 11: Designing Applications 18

Iterative development

  • Use early prototyping.
  • Frequent client interaction.
  • Iteration over:

– Analysis – Design – Prototype – Client feedback

  • A growth model is the most realistic.
slide-76
SLIDE 76

Programming 1 15/12/2005 Lecture 11: Designing Applications 4

15/12/2005 Lecture 11: Designing Applications 19

Using design patterns

  • Inter-class relationships are important, and

can be complex.

  • Some relationship recur in different

applications.

  • Design patterns help clarify relationships,

and promote reuse.

15/12/2005 Lecture 11: Designing Applications 20

Pattern structure

  • A pattern name.
  • The problem addressed by it.
  • How it provides a solution:

– Structures, participants, collaborations.

  • Its consequences.

– Results, trade-offs.

15/12/2005 Lecture 11: Designing Applications 21

Decorator

  • Augments the functionality of an object.
  • Decorator object wraps another object.

– The Decorator has a similar interface. – Calls are relayed to the wrapped object ... – ... but the Decorator can interpolate additional actions.

  • Example: java.io.BufferedReader

– Wraps and augments an unbuffered Reader object.

15/12/2005 Lecture 11: Designing Applications 22

Singleton

  • Ensures only a single instance of a class

exists.

– All clients use the same object.

  • Constructor is private to prevent external

instantiation.

  • Single instance obtained via a static

getInstance method.

  • Example: Canvas in shapes project.
15/12/2005 Lecture 11: Designing Applications 23

Factory method

  • A creational pattern.
  • Clients require an object of a particular

interface type or superclass type.

  • A factory method is free to return an

implementing-class object or subclass

  • bject.
  • Exact type returned depends on context.
  • Example: iterator methods of the

Collection classes.

15/12/2005 Lecture 11: Designing Applications 24

Observer

  • Supports separation of internal model from

a view of that model.

  • Observer defines a one-to-many

relationship between objects.

  • The object-observed notifies all Observers
  • f any state change.
  • Example SimulatorView in the foxes-

and-rabbits project.

slide-77
SLIDE 77

Programming 1 15/12/2005 Lecture 11: Designing Applications 5

15/12/2005 Lecture 11: Designing Applications 25

Observers

15/12/2005 Lecture 11: Designing Applications 26

Review

  • Class collaborations and object interactions

must be identified.

– CRC analysis supports this.

  • An iterative approach to design, analysis

and implementation can be beneficial.

– Regard software systems as entities that will grow and evolve over time.

15/12/2005 Lecture 11: Designing Applications 27

Review

  • Work in a way that facilitates collaboration

with others.

  • Design flexible, extendible class structures.

– Being aware of existing design patterns will help you to do this.

  • Continue to learn from your own and
  • thers’ experiences.

A case study

Whole-application development

1.0 15/12/2005 Lecture 11: Designing Applications 29

The case study

  • A taxi company is considering expansion.

– It operates taxis and shuttles.

  • Will expansion be profitable?
  • How many vehicles will they need?
15/12/2005 Lecture 11: Designing Applications 30

The problem description

The company operates both individual taxis and shuttles. The taxis are used to transport an individual (or small group) from one location to another. The shuttles are used to pick up individuals from different locations and transport them to their several destinations. When the company receives a call from an individual, hotel, entertainment venue, or tourist organization, it tries to schedule a vehicle to pick up the fare. If it has no free vehicles, it does not operate any form of queuing system. When a vehicle arrives at a pick-up location, the driver notifies the company. Similarly, when a passenger is dropped off at their destination, the driver notifies the company.

slide-78
SLIDE 78

Programming 1 15/12/2005 Lecture 11: Designing Applications 6

15/12/2005 Lecture 11: Designing Applications 31

Amendments

  • Purpose of the modeling suggests additions:

– Record details of lost fares. – Record details of how each vehicle passes its time.

  • These issues will help assess potential

profitability.

15/12/2005 Lecture 11: Designing Applications 32

Discovering classes

  • Singular nouns: company, taxi, shuttle,

individual, location, destination, hotel, entertainment venue, tourist organization, vehicle, fare, pickup location, driver, passenger.

  • Identify synonyms.
  • Eliminate superfluous detail.
15/12/2005 Lecture 11: Designing Applications 33

Simplified nouns and verbs

Company Operates taxis. Receives calls. Schedules a vehicle. Taxi Transports a passenger. Shuttle Transports one or more passengers. Passenger Location Vehicle Pick up individual. Arrives at pickup location. Notifies company of arrival. Notifies company of drop-off. Passenger source Calls the company.

15/12/2005 Lecture 11: Designing Applications 34

Scenarios

  • Follow a pickup through from request to

drop off with CRC cards.

PassengerSource Collaborators Create a passenger. Passenger Request a taxi. TaxiCompany Generate pickup and Location destination.

15/12/2005 Lecture 11: Designing Applications 35

Designing class interfaces

public class PassengerSource { /** * Have the source generate a new passenger and * request a pickup from the company. * @return true If the request succeeds, * false otherwise. */ public boolean requestPickup(); /** * Create a new passenger. * @return The created passenger. */ private Passenger createPassenger(); }

15/12/2005 Lecture 11: Designing Applications 36

Collaborators

  • Received through a constructor:

new PassengerSource(taxiCompany)

  • Received through a method:

taxiCompany.requestPickup(passenger)

  • Constructed within the object.

– Taxi company’s vehicle collection. – Some such objects may be passed as collaborators to other objects, as above.

slide-79
SLIDE 79

Programming 1 15/12/2005 Lecture 11: Designing Applications 7

15/12/2005 Lecture 11: Designing Applications 37

Outline implementation

  • Once the interfaces are complete, the
  • utline implementation can start.
  • The outline implementation tests the

adequacy of the interfaces.

– Expect to have to correct the design.

  • Lay down some basic tests that will be

repeated as development continues.

15/12/2005 Lecture 11: Designing Applications 38

Iterative development

  • Take relatively small steps towards the

completion of the overall application.

  • Mark the end of each step with a period of

testing.

– Regression test. – Fix errors early. – Revisit earlier design decisions, if necessary. – Treat errors-found as successes.

15/12/2005 Lecture 11: Designing Applications 39

Review

  • Robust software requires thoughtful

processes to be followed with integrity.

– Analyze carefully. – Specify clearly. – Design thoroughly. – Implement and test incrementally. – Review, revise and learn. Nobody’s perfect!

slide-80
SLIDE 80 ✂✁☎✄✝✆✞✄✠✟☛✡ ☞✍✌✏✎✒✑✔✓✖✕✘✗✙✎✒✚✜✛✣✢✥✤✧✦✩★✪✚✘✫ ✬✮✭✰✯✩✱✳✲✵✴✷✶✸✭✺✹☎✴✼✻✾✽❀✿❁✻✾✶✸✯✷❂✮✴❃✭✰✲❅❄❆✿❃❇❈✭✺✹❉✿❃✭ ✭❋❊✮✱✣✶✸❇☛✹☎✱●✴●❇❍✻❁✹ ✿✷✶❏■▲❑▼■▲◆P❖▼◗❃✯●✲✳✻✳❘✣✲✣✱✣✶❙✶✸❇✖✹❉❘ ■ ❚✺★❯✛✔❱❲❚✺★❯✛✮❳❨✢✔✌✞✚❩✫✣❬❭✓❯★✥✕✖❱P✤❪✕✘✢✔❫✾✫❵❴❛✤❪✕✘✢✔❫✾❫❝❜✞✚❩✢✔✫❵❴❛✚❩✢✥❫ ❞❢❡●❣✝❤❥✐❦❣✝❧▲✐❦❤❯♠✜❡❥♥♣♦rq✵❤❈s✉t✏✈✇t▲♥①❡❍❧✞②❍③✪♠r④❦⑤❝❤❥⑤⑦⑥❁❧⑦♦①✈✠⑥⑨⑧ ⑩▲❧⑦✐❦✐❲q✵❤❯♥♣❶✥♦✂❷❢④❦✐❦✐❸t✏✈✇②❍④❦❹❥✈✠⑤❝❺✒❡❥♥❻❣❩❡❥♥①♥①✈✠❣❩♠❭❤❥⑤▲♦✜❷❆✈✝♥✙♦✂♠✜❡●❼r❽❻❾❭❿❆❿➁➀✥❧✞✈✠♦✜♠①④➂❡❍⑤⑦♦✠⑧ ➃ ⑤⑦✐➂s✵♠①③⑦✈➄tP✈✠♦✜♠✂♠①③✞♥①✈✝✈➅❤❥⑤▲♦✜❷❆✈✝♥✙♦✂❷❭④❦✐❦✐✏❣❩❡❍⑤✪♠✜♥♣④➂t▲❧✞♠✜✈➅♠✜❡❈❷➆❤❯♥♣⑥⑦♦r♠①③⑦✈➄❤❥♦①♦✜✈✠♦①♦①q✵✈✠⑤➇♠✝⑧ ✂✁☎✄✝✆✞✄✠✟☛✡
slide-81
SLIDE 81 ✂✁☎✄✝✆✞✄✠✟☛✡
✄ ⑧ ✁ ❤✄✂✆☎ ♦✂♠①③✞✈➄❺ ❡❍✐❦✐➂❡✖❷❭④❦⑤✞②✺♦✜♠①❤❯♠✜✈✠q✺✈✠⑤✪♠❭♠✜♥✙❧✞✈✇❡❥♥r❺ ❤❥✐❦♦✜✈✞✝✠✟❆♥✙④➂✈☛✡⑦s✷✈✌☞✎✍▲✐ ❤❥④❦⑤✷s❥❡❍❧✞♥❢❤❥⑤⑦♦①❷❆✈✝♥✠⑧ ✏✒✑✓✑ ✟ ④❦♦✂♠①③✞✈➄♦♣❤❥q✺✈➅❤❥♦✔✟ ✑✓✑✕✏ ❺ ❡❥♥❢❤❥⑤✪s✖✟✧❡✥❡❍✐➂✈✠❤❥⑤❁✈✌☞✗✍⑦♥①✈✠♦♣♦①④➂❡❍⑤⑦♦ ✏ ❤❥⑤⑦⑥✘✟❻⑧ ✙✛✚✞✜ ✁ t✢✂✤✣✣♥♣④➂♠✜✈ ❤✥✍⑦♥♣❡❥②❥♥♣❤❥q ♠①③▲❤❯♠●♥①✈✠❤❥⑥⑦♦❃④❦⑤➁❤☎♦✜✈✝♥♣④➂✈✠♦●❡❥❺✦✡⑦❡❍❤❯♠①④❦⑤✞②★✧✩✍P❡❍④❦⑤✪♠●⑤✥❧⑦q➅tP✈✝♥♣♦❃❤❥⑤⑦⑥✪✍▲♥♣④❦⑤✪♠①♦✺❡❍❧✞♠ ♠①③✞✈ q✵④❦⑤⑦④❦q✰❧⑦q✬✫✧q✵❤✭☞✞④❦q✍❧▲q ❤❥⑤⑦⑥ ❤✠❹❥✈✝♥♣❤❯②❥✈✳❹❯❤❥✐❦❧✞✈✠♦✝⑧ ✏ ♦①♦①❧▲q✺✈✾❧⑦♦✜✈ ❡❥❺✇♠①③✞✈
  • ❡❍⑤⑦♦✜❡❍✐➂✈✠❾❭✈✠❤❥⑥✞✈✝♥
❣✝✐❦❤❥♦①♦✠⑧ ✙✯✮✰✜ ✁ ❣✰✂ ✣✣♥♣④➂♠✜✈ ❤✣q✺✈✝♠①③✞❡✔⑥ ♠①③⑦❤❯♠●❣❩❡❍q✱✍▲❧⑦♠✜✈✠♦✺♠①③✞✈✾❤❥✐➂♠✜✈✝♥✙⑤⑦❤❯♠①④❦⑤✞②✣♦①❧⑦q ❡❥❺✇❤❥✐❦✐✧✈✠✐➂✈✠q✵✈✠⑤➇♠①♦❃④❦⑤ ❤❥⑤❉④❦⑤✪♠✜✈✝②❥✈✝♥ ❤❯♥①♥♣❤❈s❥⑧❢⑩✞❡❥♥✩✈✌☞✞❤❥q✱✍▲✐➂✈✲✫P④➂❺❵♠①③✞✈✰q✺✈✝♠①③✞❡✔⑥ ④❦♦❢④❦⑤✪❹❥❡❥❶❥✈✠⑥✾❷❭④❦♠①③❁♠①③✞✈❋❤❯♥①♥♣❤❈s❁❣❩❡❍⑤➇♠①❤❥④❦⑤▲④❦⑤✞② ✟✾✄➅✡✳✵✴✖✶
✟ ♠①③⑦✈✠⑤❁④➂♠✂♥①✈✝♠①❧✞♥✙⑤⑦♦ ✟✔✷ ✄❩✡✸✷✪✲✴✹✷✺✶✲✹✷ ✚ ✟✼✻ ✮ ⑧ ✙✯✮✰✜
✁ ❤✄✂✆✣✣♥♣④➂♠✜✈❻❤➅♦①④ q✱✍▲✐➂✈✽✟➆❤❥⑤✞❶ ✏ ❣✝❣❩❡❍❧⑦⑤➇♠➆❣✝✐❦❤❥♦①♦ ♠①③⑦❤❯♠ ♥♣✈✿✾ ✈✠❣❩♠①♦✧⑤✞✈✝②❍❤❯♠①④➂❹❥✈✩❤❥q✺❡❍❧⑦⑤✪♠①♦ ④❦⑤●♠①③✞✈❭⑥✞✈☛✍P❡❍♦①④❦♠ ❤❥⑤⑦⑥ ❷❭④➂♠①③▲⑥✞♥♣❤✠❷ q✺✈✝♠①③✞❡✔⑥⑦♦▼❤❥⑤⑦⑥●♥①✈✿✾ ✈✠❣❩♠①♦❆❷❭④➂♠①③▲⑥✞♥♣❤✠❷➆❤❥✐❦♦❵♠①③⑦❤❯♠❆❷❆❡❍❧▲✐❦⑥✺♥①✈✠♦①❧▲✐➂♠▼④❦⑤✵❤❥⑤●❡❈❹❥✈✝♥♣⑥✞♥✙❤❯❺✒♠✝⑧ ✙✯✮✰✜ ✁ t✢✂✤✣ ③⑦❤❯♠❭④❦♦✂❷❭♥①❡❍⑤✞②✺❷❭④➂♠①③✉♠①③⑦✈✇❺✒❡❍✐❦✐❦❡❈❷❭④❦⑤⑦②❋✐❦❡✪❡✲✍✢✝✾❿❀☞✗✍▲✐❦❤❥④ ⑤
  • ❷➆❤✠s✔♦❢❡❥❺❂❁❃☞✞④❦⑤✞②❋♠①③✞✈➅✈✝♥①♥①❡❥♥✠⑧
❄✞❅✗❆✽❇❉❈❋❊❍●■❅❑❏▼▲✒❄✰❅❃❆◆❇P❖✭◗❘❈❚❙ ❯✗❱▼❲❨❳☛❄✰❅❃❆❩❄❬●❭❖❪❙❫❄❋❴▼●✕❖✭◗❚❙❫❄★❵✎❵❜❛ ❊✽❇❝❄✲❈❞●❡❄❘❢✎❄❣❙ ✙✛✚✞✜ ✁ ❣✰✂ ⑩✞❡❥♥❢✈✠❤❥❣♣③ ❡❥❺ ♠①③✞✈➅❺✒❡❍✐❦✐❦❡❈❷❭④❦⑤⑦②❃✫✔♦♣❤✠s❝④➂❺ ④❦♠r④❦♦✂♠✜♥♣❧✞✈✇❡❥♥❭❺ ❤❥✐❦♦①✈❥⑧ ✁ ❤✄✂ ✏ ♥①♥✙❤✠s✉♦①❧✞t▲♦①❣❩♥✙④❤✍⑦♠①♦➆q✍❧▲♦✜♠rtP✈✇④❦⑤➇♠✜✈✝②❥✈✝♥✙♦ ✁ t✢✂ ✏ ♥①♥✙❤✠s✔♦r❣✝❤❥⑤⑦⑤✞❡❥♠❭❣❩❡❍⑤✪♠①❤❥④❦⑤❥✐✥♠✜♥♣④❦⑤✞②❍♦✂❤❥♦r✈✠✐➂✈✠q✺✈✠⑤✪♠①♦ ✁ ❣✰✂ ✏ ♥①♥✙❤✠s✔♦r❣✝❤❥⑤⑦⑤✞❡❥♠❭❧▲♦✜✈✼✐✥♠✜♥♣④❦⑤⑦②❍♦✂❤❥♦❭♦①❧✞t❸♦①❣❩♥♣④❤✍⑦♠①♦ ✁ ⑥❜✂❧❦ ❤❯♥✙❤❥✐❦✐➂✈✠✐⑨❤❯♥①♥♣❤❈s✥♦❢q✍❧▲♦✜♠r③⑦❤✠❹❥✈✍✈✠➀✪❧▲❤❥✐⑨✐➂✈✠⑤✞②❥♠①③ ✁ ✈✞✂ ❼✂❷❆❡★✧ ⑥▲④❦q✺✈✠⑤⑦♦①④❦❡❍⑤⑦❤❥✐P❤❯♥①♥♣❤✠s✔♦r❤❥✐➂❷➆❤✠s✔♦❭③▲❤✠❹❥✈➅♠①③⑦✈➅♦①❤❥q✺✈➄⑤✥❧⑦q✍t✏✈✝♥✂❡❥❺❵♥①❡✖❷❭♦r❤❥⑤⑦⑥✾❣❩❡❍✐❦❧⑦q✵⑤⑦♦ ✁ ❺P✂ ❼✂❷❆❡✱✍❸❤❯♥♣❤❥✐❦✐➂✈✠✐⑨❤❯♥①♥✙❤✠s✔♦r❣✝❤❥⑤❁tP✈✇♥①✈☛✍▲✐ ❤❥❣❩✈✠⑥❝t✪s✷❡❍⑤✞✈➄♠ ❷❆❡★✧ ⑥▲④❦q✺✈✠⑤⑦♦①④❦❡❍⑤⑦❤❥✐⑨❤❯♥①♥♣❤❈s ✁ ②❘✂ ❿ ✐➂✈✠q✺✈✠⑤✪♠①♦❋❡❥❺✩⑥⑦④♥♠P✈✝♥①✈✠⑤➇♠✺❣❩❡❍✐❦❧▲q✵⑤⑦♦❋④❦⑤ ❤✳♠ ❷✧❡★✧ ⑥⑦④❦q✺✈✠⑤▲♦①④➂❡❍⑤⑦❤❥✐➆❤❯♥①♥♣❤❈s ❣✝❤❥⑤➁③⑦❤✠❹❥✈❁⑥⑦④❤♠✏✈✝♥①✈✠⑤✪♠ ♠ s✎✍✏✈✠♦ ✙✯✮✰✜ ✂✁☎✄✝✆✞✄✠✟☛✡ ❣❩❡❍⑤✪♠①④❦⑤✥❧✞✈✠⑥
slide-82
SLIDE 82 ✂✁☎✄✝✆✞✄✠✟☛✡ ❣❩❡❍⑤✪♠①④❦⑤✥❧✞✈✠⑥ ✟ ⑧ ✟ ⑧ ✁ ❤✄✂ ❿❀☞✗✍▲✐❦❤❥④ ⑤●♠①③✞✈✇⑥⑦④❤♠✏✈✝♥①✈✠⑤▲❣❩✈❢tP✈✝♠ ❷✧✈✝✈✠⑤❁❣✝✐❦❤❥♦♣♦✂❤❥⑤⑦⑥✉④❦⑤⑦♦✜♠①❤❥⑤⑦❣❩✈✇q✺✈✝♠①③⑦❡✥⑥⑦♦✁☛q✺✈✠q➅tP✈✝♥♣♦✠⑧❵❽❢❡❈❷ ❣✝❤❥⑤✉♠①③⑦④❦♦ tP✈✇✈✌☞✎✍▲♥①✈✠♦①♦✜✈✠⑥❁④ ⑤✉s❥❡❍❧✞♥❭❣❩❡✔⑥✞✈✞✝ ✙✛✚✞✜ ✁ t✢✂
  • ❤❥⑤
❣✝✐❦❤❥♦♣♦ q✵✈✝♠①③✞❡✥⑥▲♦✂☛q✺✈✠q✍t✏✈✝♥✙♦ tP✈ ❧⑦♦✜✈✠⑥ ④❦⑤ ④❦⑤⑦♦①♠①❤❥⑤⑦❣❩✈❀q✺✈✝♠①③✞❡✔⑥⑦♦P✝ ❿❀☞✗✍▲✐❦❤❥④❦⑤ ❷❭③➇s ✁ ⑤✞❡❥♠P✂✙⑧ ✙
✁ ❣✰✂
  • ❤❥⑤
❣✝✐❦❤❥♦①♦ ④❦⑤⑦♦①♠①❤❥⑤⑦❣❩✈ q✵✈✝♠①③✞❡✥⑥▲♦✂☛q✺✈✠q✍t✏✈✝♥✙♦✾tP✈☎❧▲♦✜✈✠⑥ ④ ⑤ ❣✝✐❦❤❥♦♣♦ q✺✈✝♠①③⑦❡✥⑥⑦♦ ✝ ❿❀☞✗✍▲✐❦❤❥④❦⑤ ❷❭③➇s ✁ ⑤✞❡❥♠P✂✙⑧ ✙
✁ ⑥❜✂✤☎ ⑤✍♦✜❡❥❺ ♠ ❷➆❤❯♥①✈✂✈✠⑤✞②❍④ ⑤✞✈✝✈✝♥♣④❦⑤✞②❃✫❯♦✜❡❍✐❦❧⑦♠①④➂❡❍⑤⑦♦❲♠✜❡✇❣❩❡❍q✵q✵❡❍⑤✰⑥⑦✈✠♦①④➂②❍⑤✼✍⑦♥①❡❥t▲✐➂✈✠q●♦ ❤❯♥①✈➆❡❥❺ ♠✜✈✠⑤✰❣✝❤❥✐ ✐➂✈✠⑥✍⑥⑦✈✠♦①④➂②❍⑤ ✍▲❤❯♠✜♠✜✈✝♥♣⑤▲♦✝⑧ ➃ ⑤✞✈❋❡❥❺❆♠①③✞✈✠q❀④❦♦✩❣✝❤❥✐❦✐➂✈✠⑥✥✐✔④❦⑤⑦②❍✐➂✈✝♠✜❡❍⑤ ❤❥⑤▲⑥✣④➂♠❻⑥⑦✈✠♦①❣❩♥♣④➂tP✈✠♦❻③✞❡❈❷ ❡❍⑤✞✈✵❣✝❤❥⑤✣q●❤❯❶❥✈✵♦①❧✞♥①✈ ♠①③⑦❤❯♠✇❤✉❣❩✈✝♥①♠①❤❥④❦⑤✳❣✝✐❦❤❥♦①♦✩❣✝❤❥⑤✣③⑦❤❈❹❥✈❋❡❍⑤⑦✐➂s❁❡❍⑤✞✈❋④❦⑤⑦♦①♠①❤❥⑤⑦❣❩✈✰⑥▲❧✞♥♣④❦⑤✞②❃❤✵✍▲♥①❡❥②❥♥♣❤❥q☎✄❛♦✩✐❦④➂❺ ✈✌✧ ❣❩s✔❣✝✐➂✈❥⑧✇❽❭❡✖❷ ❷✧❡❍❧⑦✐❦⑥✉s❥❡❍❧✾④ q✱✍▲✐➂✈✠q✺✈✠⑤✪♠✂♦①❧⑦❣✙③❁❤✵✐✔④❦⑤⑦②❍✐➂✈✝♠✜❡❍⑤❝❣✝✐❦❤❥♦①♦r④ ⑤✝✆❍❤✠❹❯❤✄✝ ✙✟✞✞✜ ✁ ✈✞✂ ❽❢❡❈❷ ❷✧❡❍❧⑦✐❦⑥✉s❥❡❍❧ ❣♣③✞✈✠❣♣❶❝♠①③⑦❤❯♠rs❥❡❍❧ ❣✝❤❥⑤❁④❦⑤⑦⑥✞✈✝✈✠⑥❝③▲❤✠❹❥✈➅❡❍⑤▲✐➂s●❡❍⑤✞✈✍④❦⑤⑦♦✜♠①❤❥⑤⑦❣❩✈✞✝ ✙
✡ ⑧ ✁ ❤✄✂ ❿❀☞✗✍▲✐❦❤❥④ ⑤❃♠①③⑦✈➄❺✒❡❍✐ ✐➂❡❈❷❭④ ⑤✞②✺✐❦④❦⑤✞✈✠♦✧❡❥❺ ❣❩❡✥⑥⑦✈ ✁ s❥❡❍❧✾❣✝❤❥⑤✾❤❥♦♣♦①❧⑦q✺✈✇♠①③✞✈✝s❝❤❯♥①✈✍❣❩❡❥♥①♥①✈✠❣❩♠P✂✂✠ ✁ ④ ✂ ✍▲❧✞t▲✐❦④ ❣❭♦✜♠①❤❯♠①④❦❣✓❁▲⑤⑦❤❥✐⑨⑥✞❡❍❧✞t❸✐➂✈ ❦❚☎ ✻ ✟ ⑧ ✄❩✡☛✡ ✁ ④❦④ ✂ ✍⑦♥①❡❥♠✜✈✠❣❩♠✜✈✠⑥✘❁❸⑤⑦❤❥✐P❹❥❡❍④❦⑥✬✍⑦♥✙④❦⑤➇♠P✐✔♠✜♥♣④❦⑤✞②❑✁ ❣✙③⑦❤❯♥✂❤✄✂ ✁ ④❦④❦④ ✂■✍⑦♥♣④➂❹❯❤❯♠✜✈ ✟✧❤❥⑤⑦❶ ✏ ❣✝❣❩❡❍❧⑦⑤✪♠✰✁✩✂ ✙ ✟ ✜ ✁ t✢✂✌☞❻✈✠♦①❣❩♥♣④➂tP✈✇♠①③✞✈➄q✵✈✠❣♣③⑦❤❥⑤⑦④ ♦①q✸❡❥❺❵✈✝♥①♥①❡❥♥✁✖✈✌☞✞❣❩✈☛✍⑦♠①④➂❡❍⑤✾③⑦❤❥⑤⑦⑥⑦✐❦④ ⑤✞②✰④ ⑤✼✾✜❤❈❹☛❤✔⑧ ✙✯✮✰✜ ✁ ❣✰✂ ✣ ③➇s✮❷✧❡❍❧⑦✐❦⑥❨❡❍⑤✞✈❃❧▲♦✜✈●✈✝♥①♥♣❡❥♥✰③⑦❤❥⑤▲⑥⑦✐❦④❦⑤✞②❁④ ⑤❨❤✾❣❩❡❍⑤▲♦✜♠✜♥♣❧⑦❣❩♠✜❡❥♥ ✝ ✣ ③⑦❤❯♠✰❷❭④❦✐❦✐ ③▲❤★✍ ✍P✈✠⑤✮❷❭④➂♠①③❨♠①③✞✈ ✁ ✍▲❤❯♥①♠①④ ❤❥✐ ✂❆❡❥t✗✾✜✈✠❣❩♠P✝ ✙ ✡ ✜ ✁ ⑥❜✂ ✁ ④ ✂ ❿❀☞✗✍▲✐❦❤❥④❦⑤ ♠①③✞✈✺⑥⑦④♥♠P✈✝♥①✈✠⑤⑦❣❩✈✠♦❻tP✈✝♠ ❷✧✈✝✈✠⑤✮❣✝❤❥✐❦✐♥✧❪t✥s❘✧❪♥①✈✝❺✒✈✝♥♣✈✠⑤⑦❣❩✈✺❤❥⑤⑦⑥✣❣✝❤❥✐❦✐♥✧❪t✥s✄✧❪❹❯❤❥✐❦❧✞✈ ✍▲❤❯♥♣❤❥q✵✈✝♠✜✈✝♥ ✍▲❤❥♦①♦①④❦⑤⑦②❘✝ ✁ ④❦④ ✂ ✣ ③⑦④ ❣♣③❁♦✜s✔♦✜♠✜✈✠q✵♦❭❤❯♥①✈➅❧⑦♦✜✈✠⑥❝④ ⑤✝✆❍❤✠❹❯❤✄✝ ✙✛✚✞✜ ✂✁☎✄✝✆✞✄✠✟☛✡ ❣❩❡❍⑤✪♠①④❦⑤✥❧✞✈✠⑥
slide-83
SLIDE 83 ✂✁☎✄✝✆✞✄✠✟☛✡ ❣❩❡❍⑤✪♠①④❦⑤✥❧✞✈✠⑥ ✡ ⑧ ✴ ⑧ ✁ ❤✄✂
  • ❡❍⑤⑦♦♣④❦⑥✞✈✝♥❻♠①③✞✈✍❺
❡❍✐❦✐➂❡✖❷❭④❦⑤✞②❃❺✒❡❍❧⑦♥❻❣✝✐❦❤❥♦♣♦✜✈✠♦✝⑧ ✟✧s ❤❥❣✝❣✝④❦⑥✞✈✠⑤✪♠ ✄ ✴ ✈✝♥①♥①❡❥♥♣♦✩♦①✐❦④ ✍ ✍P✈✠⑥❁④❦⑤⑨⑧ ☞❢✈✝♠✜✈✠❣❩♠➅♠①③✞✈✠q ❤❥⑤⑦⑥❝✈✌☞✗✍▲✐❦❤❥④ ⑤✉❷❭③➇s❃♠①③✞✈✝s❝❤❯♥①✈➄✈✝♥①♥♣❡❥♥♣♦✝⑧ ❣✝✐❦❤❥♦①♦❭❾❭❧⑦⑤ ❖ ✁ ❄ ✂☎✄ ❱✄❲❘❆✝✆☎✞✲❊✟✞ ✁✡✠ ❆❑❄☞☛ ✁ ❢❣❙ ✌ ✁ ✍ ✁ ✄ ✠✏✎ ☛❃❄✏✑✒✑☞☛✏✞✟✓✏✓✕✔ ✠ ❅ ✖ ✁✘✗ ✙ ✁ ✚ ✁ ✛ ❏✟✑★❆✗❱✄❲ ❏✜☛❘❏ ✂ ❏✲❅✗❆✢✓ ❙ ✣ ✁ ✤ ✁ ✄ ✠✜✎ ☛✗❄✜✑✥✔ ✠ ❅ ❳☛❄✞❅✗❆❡❄✞❅ ❛ ✦ ✁ ✗ ❖✞◗ ✁ ❄✰❅❃❆ ❆❍●✧✞❀❙ ❖❘❖ ✁ ❏✜☛❘❏ ✂ ❏✲❅✗❆✢✓
  • ❋❅
❏▼▲ ✛ ❏✟✑★❆✗❱✄❲❀❳✰❛ ❙ ❖★✌ ✁ ❯✎❱✄❲❚❳✌❄✞❅✗❆❋❆❍● ◗❚❙✘❆❡❴❃❄✰❅ ❙✘❆✎❵✎❵✢❛ ❖✩✍ ✁ ✗ ❖✪✖ ✁ ❄★❯❀❳ ❆✜✫✬✌▼●✎●✗◗❑❛ ❖ ✙ ✁ ❏✜☛❘❏ ✂ ❏✲❅✗❆✢✓ ✁ ✞☞✭✏✭✏✮✟☛✄❏ ✂ ❏✲❅❃❆❀❳ ❅ ❏▼▲✯✮✟☛✄❏ ✂ ❏✲❅❃❆✜✰❀❳✲✱✪✞✳✱★❛✎❛❪❙ ❖✩✚ ✁ ❏✜☛✟✓✲❏ ❖✩✣ ✁ ❏✜☛❘❏ ✂ ❏✲❅✗❆✢✓ ✁ ✞☞✭✏✭✏✮✟☛✄❏ ✂ ❏✲❅❃❆❀❳ ❅ ❏▼▲✯✮✟☛✄❏ ✂ ❏✲❅❃❆✏✴❚❳❝❆ ❛✎❛❪❙ ❖✩✤ ✁ ❖✩✦ ✁ ✵ ✌✄◗ ✁ ✵ ✌❑❖ ✁ ✌✏✌ ✁ ✄ ✠✜✎ ☛❃❄✏✑✷✶▼❆❘❲❜❄✞❅✬✸❋❆❃❱✜✶▼❆❘❲❜❄✞❅✬✸❀❳ ❛ ✌☞✍ ✁ ✗ ✌✹✖ ✁ ✶✲❆✎❲❜❄✰❅✟✸❋❲✗❏✺✓✪●✻✱❜❙ ✌ ✙ ✁ ❄✰❅❃❆✼✓❬● ❏☎☛✄❏ ✂ ❏✲❅❃❆✽✓ ✁ ✓❘❄✿✾✎❏ ❳ ❛ ❙ ✌☞✚ ✁ ❯✎❱✄❲❚❳✌❄✞❅✗❆ ❄✲●✎◗❚❙❫❄▼❴✟✓❂❙❫❄★❵✎❵❜❛ ✌☞✣ ✁ ✗ ✌☞✤ ✁ ❲✗❏✺✓✺❵❘● ❏✜☛❘❏ ✂ ❏✲❅✗❆✢✓ ✁ ❏☎☛✄❏ ✂ ❏✲❅❃❆✜✰❘❆❀❳☛❄❃❛❪❙ ✌☞✦ ✁ ❲✗❏✺✓✺❵❘●❀✱❂❁★❅❃✱✢❙ ✍❘◗ ✁ ✵ ✍❜❖ ✁ ❲✗❏✄❆ ✠ ❲✄❅ ❲✗❏✺✓ ❙ ✍✜✌ ✁ ✵ ✍✏✍ ✁ ✍☞✖ ✁ ✄ ✠✜✎ ☛❃❄✏✑ ✛ ❏✬✑★❆❃❱▼❲❄✸❑❄✭❊❃❏✹✮✟☛❘❏ ✂ ❏★❅❃❆✢✓ ❳✰❛ ✍ ✙ ✁ ✗ ✍✏✚ ✁ ❲✗❏✄❆ ✠ ❲✄❅ ❏✜☛❘❏ ✂ ❏✲❅✗❆✢✓ ❙ ✍✏✣ ✁ ✵ ✍✏✤ ✁ ❅❇❆✳❈❊❉✪❋❍●❏■☞❑▼▲❖◆❊■☞❑✳❋❍●P❑✳❆✳❈❊❉◗■☞❑▼❑❃❈❙❘☎❋❯❚✢❱✿❲✺❈❨❳✲❳✲❳ ✂✁☎✄✝✆✞✄✠✟☛✡ ❣❩❡❍⑤✪♠①④❦⑤✥❧✞✈✠⑥
slide-84
SLIDE 84 ✂✁☎✄✝✆✞✄✠✟☛✡ ❣❩❡❍⑤✪♠①④❦⑤✥❧✞✈✠⑥ ✴ ⑧ ✂✁☎✄✝✆✟✞✡✠☞☛✍✌✏✎✒✑✓☛✍✌✔✞✡✠✕✌☎✁✔✄✗✖✒✘✙✘✙✘ ✍✏✦ ✁ ✄ ✠✜✎ ☛❃❄✏✑❄✓✭❆✬✞▼❆❜❄✏✑✺❊❃❱❃❄✿✭ ✂ ✞❃❄✞❅ ❳ ✶✲❆✎❲❜❄✰❅✟✸ ❇ ❈ ✞▼❲☎✸✄❊ ❛ ✖✎◗ ✁ ✗ ✖✢❖ ✁ ✮✬☛❘❏ ✂ ❏✲❅✗❆✝✞
  • ■❅❑❏✲▲✝✮✟☛❘❏
✂ ❏★❅❃❆❚❳ ❛ ❙ ✖☎✌ ✁ ✔ ✠ ❅ ❲❍●■❅❑❏✲▲❄✔ ✠ ❅ ❳ ✖❜❛ ❙ ✖✜✍ ✁ ✶✛✚✢✓✭❆✗❏ ✂ ✁ ❱ ✠ ❆ ✁ ✄ ❲❜❄✰❅❃❆✬☛★❅ ❳❝❲ ❛❪❙ ✖✏✖ ✁ ✮✬☛❘❏ ✂ ❏✲❅✗❆☎✰ ✎
  • ■❅
❏▼▲✝✮✟☛✄❏ ✂ ❏✲❅❃❆❀❳ ✙ ❛ ❙ ✖ ✙ ✁◗✛ ❏✟✑★❆✗❱✄❲ ❏✜☛❋● ❲ ✁ ✸❑❄★❊✗❏☞✮✬☛❘❏ ✂ ❏✲❅✗❆✢✓❪❳ ❛ ❙ ✖✜✚ ✁ ✶✛✚✢✓✭❆✗❏ ✂ ✁ ❱ ✠ ❆ ✁ ✄ ❲❜❄✰❅❃❆✬☛★❅ ❳❘❳ ✮✬☛❘❏ ✂ ❏✲❅✎❆☎✰❜❛❫❏☎☛ ✁ ❏✜☛❘❏ ✂ ❏✲❅✗❆☎✰❘❆❀❳✞❖✄❛✎❛ ❙ ✖✜✣ ✁ ✖✜✤ ✁ ✵ ✖✜✦ ✁ ✙ ◗ ✁ ✵ ❣✝✐❦❤❥♦①♦❭❿ ✐➂✈✠q✺✈✠⑤✪♠ ❖ ✁✢✜✣✜ ✞ ✎ ✓✭❆✎❲✬✞✬✑✭❆ ✑☞☛✏✞✟✓✜✓✕✮✟☛❘❏ ✂ ❏★❅❃❆ ✌ ✁ ✍ ✁ ✄ ✠✜✎ ☛✗❄✜✑✯✞ ✎ ✓✞❆✎❲✬✞✬✑★❆ ✑☞☛✜✞✬✓✜✓✥✮✬☛❘❏ ✂ ❏✲❅✗❆ ✖ ✁ ✗ ✙ ✁ ✚ ✁ ✣ ✁ ✄ ✠✜✎ ☛✗❄✜✑▼✮✬☛❘❏ ✂ ❏✲❅✗❆❚❳ ❛ ✤ ✁ ✗ ✦ ✁ ✶✤✚✽✓✭❆❃❏ ✂ ✁ ❱ ✠ ❆ ✁ ✄ ❲❜❄✞❅✗❆✟☛✭❅ ❳✿✱ ✮✟☛✄❏ ✂ ❏✲❅❃❆✷✑★❲❃❏✜✞▼❆✗❏✏✭ ✱★❛ ❙ ❖✞◗ ✁ ✵ ❖❘❖ ✁ ❖★✌ ✁ ✄ ❲❃❱▼❆❃❏✬✑★❆❃❏☞✭❄✞ ✎ ✓✭❆❘❲✟✞☎✑★❆✧✶✲❆✎❲❜❄✰❅✟✸ ✄ ❲❜❄✰❅❃❆✦✥❘❱✲❅✗❆❃❏✲❅✗❆✢✓ ❳✰❛ ❙ ❖✩✍ ✁ ❖✪✖ ✁ ❖ ✙ ✁ ✄ ❲❃❱▼❆❃❏✬✑★❆❃❏☞✭❄✶✲❆✎❲❜❄✰❅✟✸ ✄ ❲❜❄✰❅❃❆★✧✣✚ ✄ ❏ ❳✰❛ ❖✩✚ ✁ ✗ ❖✩✣ ✁ ❲✗❏✄❆ ✠ ❲✄❅❀✱ ✮✟☛✄❏ ✂ ❏★❅❃❆ ✱ ❖✩✤ ✁ ✵ ❖✩✦ ✁ ✌✄◗ ✁ ✄ ✠✜✎ ☛❃❄✏✑✷✶▼❆❘❲❜❄✞❅✬✸❋❆❃❱✜✶▼❆❘❲❜❄✞❅✬✸❀❳ ❛ ✌❑❖ ✁ ✗ ✌✏✌ ✁ ✄ ❲❜❄✞❅✗❆★✧✣✚ ✄ ❏❣❳✰❛❪❙ ✌☞✍ ✁ ✵ ✌✹✖ ✁ ✌ ✙ ✁ ✵ ❅❇❆✳❈❊❉✪❋❍●❏■☞❑▼▲❖◆❊■☞❑✳❋❍●P❑✳❆✳❈❊❉◗■☞❑▼❑❃❈❙❘☎❋❯❚✢❱✿❲✺❈❨❳✲❳✲❳ ✂✁☎✄✝✆✞✄✠✟☛✡ ❣❩❡❍⑤✪♠①④❦⑤✥❧✞✈✠⑥
slide-85
SLIDE 85 ✂✁☎✄✝✆✞✄✠✟☛✡ ❣❩❡❍⑤✪♠①④❦⑤✥❧✞✈✠⑥ ✚ ⑧ ✂✁☎✄✝✆✟✞✡✠☞☛✍✌✏✎✒✑✓☛✍✌✔✞✡✠✕✌☎✁✔✄✗✖✒✘✙✘✙✘ ❣✝✐❦❤❥♦①♦❭❿ ✐➂✈✠q✺✈✠⑤✪♠ ✏ ❖ ✁✢✜✣✜ ✄ ✠✏✎ ☛❃❄✏✑✒✑☞☛✏✞✟✓✏✓▼✮✟☛❘❏ ✂ ❏★❅❃❆☎✰ ✌ ✁ ✍ ✁ ✄ ✠✜✎ ☛✗❄✜✑✷✑☞☛✜✞✬✓✜✓▼✮✬☛❘❏ ✂ ❏✲❅✗❆☎✰ ❏✁❘❆✗❏✲❅✟✭✷✮✟☛❘❏ ✂ ❏★❅❃❆ ✖ ✁ ✗ ✙ ✁ ✶✲❆✎❲❜❄✰❅✟✸❞❏✜☛❀❙ ✚ ✁ ✣ ✁ ✄ ✠✜✎ ☛✗❄✜✑▼✮✬☛❘❏ ✂ ❏✲❅✗❆☎✰ ❳✰❛ ✤ ✁ ✗ ✦ ✁ ✶✤✚✽✓✭❆❃❏ ✂ ✁ ❱ ✠ ❆ ✁ ✄ ❲❜❄✞❅✗❆✟☛✭❅ ❳✿✱ ✮✟☛✄❏ ✂ ❏✲❅❃❆✏✰ ✑★❲✗❏☎✞✲❆❃❏✏✭ ✱✲❛❪❙ ❖✞◗ ✁ ❏✜☛❋●✻✱P❅❑❱▼❆✁✂✢❄✞❅✟✸ ✱✢❙ ❖❘❖ ✁ ✵ ❖★✌ ✁ ❖✩✍ ✁ ✄ ✠✜✎ ☛❃❄✏✑▼✮✟☛✄❏ ✂ ❏★❅❃❆✜✰❀❳ ✶✲❆✎❲❑❄✞❅✟✸ ❄✰❅ ✄ ✠ ❆ ❛ ❖✪✖ ✁ ✗ ❖ ✙ ✁ ✶✛✚✢✓✭❆✗❏ ✂ ✁ ❱ ✠ ❆ ✁ ✄ ❲❜❄✰❅❃❆✬☛★❅ ❳✲✱ ✮✬☛❘❏ ✂ ❏✲❅✎❆☎✰ ✑✭❲❃❏✜✞▼❆❃❏☞✭❬▲❜❄★❆✁✂✕❄✰❅ ✄ ✠ ❆ ✱★❛ ❙ ❖✩✚ ✁ ❏✜☛❋●❡❄✞❅ ✄ ✠ ❆ ❙ ❖✩✣ ✁ ✵ ❖✩✤ ✁ ❖✩✦ ✁ ✜ ❢ ✄ ❲✗❱✄❆✗❏✟✑★❆✗❏✏✭✝✑▼❱✲❅ ✓✭❆❘❲ ✠ ✑✭❆❃❱▼❲ ❢ ✜ ✌✄◗ ✁ ✄ ❲❃❱▼❆❃❏✬✑★❆❃❏☞✭✷✮✬☛❘❏ ✂ ❏✲❅✗❆☎✰❀❳❙✞❑❛ ✌❑❖ ✁ ✗ ✌✏✌ ✁ ✶✛✚✢✓✭❆✗❏ ✂ ✁ ❱ ✠ ❆ ✁ ✄ ❲❜❄✰❅❃❆✬☛★❅ ❳✲✱ ✮✬☛❘❏ ✂ ❏✲❅✎❆☎✰ ✑✭❲❃❏✜✞▼❆❃❏☞✭❬▲❜❄★❆✁✂✕❄✰❅❃❆ ✱✲❛ ❙ ✌☞✍ ✁ ❏✜☛❋●☎✄✰❅❃❆✗❏✏✸✎❏✄❲ ✁ ❆❃❱✜✶▼❆✎❲❑❄✞❅✬✸❀❳ ✞ ❛ ❙ ✌✹✖ ✁ ✵ ✌ ✙ ✁ ✌☞✚ ✁ ✄ ❲❃❱▼❆❃❏✬✑★❆❃❏☞✭❄✶✲❆✎❲❜❄✰❅✟✸ ✄ ❲❜❄✰❅❃❆✦✥❘❱✲❅✗❆❃❏✲❅✗❆✢✓ ❳✰❛ ✌☞✣ ✁ ✗ ✌☞✤ ✁ ❲✗❏✄❆ ✠ ❲✄❅ ❏✜☛❀❙ ✌☞✦ ✁ ✵ ✍❘◗ ✁ ✍❜❖ ✁ ✄ ❲❃❱▼❆❃❏✬✑★❆❃❏☞✭❄✶✲❆✎❲❜❄✰❅✟✸ ✄ ❲❜❄✰❅❃❆★✧✣✚ ✄ ❏ ❳✰❛ ✍✜✌ ✁ ✗ ✍✏✍ ✁ ❲✗❏✄❆ ✠ ❲✄❅❀✱ ✮✟☛✄❏ ✂ ❏★❅❃❆✜✰❍❄✞❅✆✂❑❏▼❲❜❄★❆✽✓ ❯✄❲❃❱ ✂ ✱ ✓ ✠ ✄ ❏✄❲ ✁ ✄ ❲❜❄✞❅✗❆★✧✣✚ ✄ ❏❣❳✰❛❪❙ ✍☞✖ ✁ ✵ ✍ ✙ ✁ ✍✏✚ ✁ ✄ ✠✜✎ ☛❃❄✏✑✷✶▼❆❘❲❜❄✞❅✬✸❋❆❃❱✜✶▼❆❘❲❜❄✞❅✬✸❀❳ ❛ ✍✏✣ ✁ ✗ ✍✏✤ ✁ ❲✗❏✄❆ ✠ ❲✄❅ ✄ ❲❜❄✰❅❃❆★✧✣✚ ✄ ❏ ❳✰❛ ❵ ✍✏✦ ✁ ✱❂✞★❅✟✭ ✑✲❱✲❅✗❆✟✞❃❄✰❅✳✓ ✱ ❵ ✄ ❲❜❄✞❅✗❆✦✥❘❱✲❅❃❆✗❏✲❅✗❆✢✓❪❳ ❛ ❙ ✖✎◗ ✁ ✖✢❖ ✁ ✖☎✌ ✁ ✵ ❅❇❆✳❈❊❉✪❋❍●❏■☞❑▼▲❖◆❊■☞❑✳❋❍●P❑✳❆✳❈❊❉◗■☞❑▼❑❃❈❙❘☎❋❯❚✢❱✿❲✺❈❨❳✲❳✲❳ ✂✁☎✄✝✆✞✄✠✟☛✡ ❣❩❡❍⑤✪♠①④❦⑤✥❧✞✈✠⑥
slide-86
SLIDE 86 ✂✁☎✄✝✆✞✄✠✟☛✡ ❣❩❡❍⑤✪♠①④❦⑤✥❧✞✈✠⑥ ✮ ⑧ ✂✁☎✄✝✆✟✞✡✠☞☛✍✌✏✎✒✑✓☛✍✌✔✞✡✠✕✌☎✁✔✄✗✖✒✘✙✘✙✘ ❣✝✐❦❤❥♦①♦❭❿ ✐➂✈✠q✺✈✠⑤✪♠ ✟ ❖ ✁✢✜ ✄ ✠✜✎ ☛✗❄✜✑✒✑✹☛✜✞✬✓✜✓✥✮✬☛❘❏ ✂ ❏✲❅✗❆✜✴ ✌ ✁ ✍ ✁ ✖ ✁ ✙ ✁ ✄ ✠✜✎ ☛✗❄✜✑✷✑☞☛✜✞✬✓✜✓▼✮✬☛❘❏ ✂ ❏✲❅✗❆✜✴❞❏✁❘❆✗❏✲❅✟✭✺✓✥✮✟☛✄❏ ✂ ❏✲❅❃❆✜✰ ✚ ✁ ✗ ✣ ✁ ✤ ✁ ✛ ❏✟✑★❆✗❱✄❲❡❄✰❅ ❙ ✦ ✁ ❖✞◗ ✁ ✄ ✠✜✎ ☛❃❄✏✑▼✮✟☛✄❏ ✂ ❏★❅❃❆✏✴❚❳✰❛ ❖❘❖ ✁ ✗ ❖★✌ ✁ ✶✛✚✢✓✭❆✗❏ ✂ ✁ ❱ ✠ ❆ ✁ ✄ ❲❜❄✰❅❃❆✬☛★❅ ❳✲✱ ✮✬☛❘❏ ✂ ❏✲❅✎❆✜✴✒✑✭❲❃❏✜✞▼❆❃❏☞✭ ✱★❛ ❙ ❖✩✍ ✁ ❄✰❅
  • ■❅❑❏▼▲
✛ ❏✟✑✭❆❃❱✄❲❀❳✰❛❪❙ ❖✪✖ ✁ ✵ ❖ ✙ ✁ ❖✩✚ ✁ ❖✩✣ ✁ ✄ ✠✜✎ ☛❃❄✏✑▼✮✟☛✄❏ ✂ ❏★❅❃❆✏✴❚❳ ✶✲❆✎❲❑❄✞❅✟✸❬❏✜☛❑❛ ❖✩✤ ✁ ✗ ❖✩✦✝✶✤✚✽✓✭❆❃❏ ✂ ✁ ❱ ✠ ❆ ✁ ✄ ❲❜❄✞❅✗❆✟☛✭❅ ❳✿✱ ✮✟☛✄❏ ✂ ❏✲❅❃❆☞✴✒✑★❲✗❏☎✞✲❆❃❏✏✭❬▲✢❄★❆ ✂✒❄✞❅ ✄ ✠ ❆ ✱✲❛❪❙ ✌✄◗ ✁ ✓ ✠ ✄ ❏▼❲❚❳ ❏☎☛❑❛❪❙ ✌❑❖ ✁ ✌✏✌ ✁ ✵ ✌☞✍ ✁ ✌✹✖ ✁ ✄ ✠✜✎ ☛❃❄✏✑▼✮✟☛✄❏ ✂ ❏★❅❃❆✏✴❚❳☛❄✰❅❃❆✒✞❑❛ ✌ ✙ ✁ ✗ ✌☞✚ ✁ ✓ ✠ ✄ ❏▼❲❚❳❙✞❑❛ ❙ ✌☞✣ ✁ ✶✛✚✢✓✭❆✗❏ ✂ ✁ ❱ ✠ ❆ ✁ ✄ ❲❜❄✰❅❃❆❀❳✿✱ ✮✬☛❘❏ ✂ ❏✭❅❃❆✜✴✷✑★❲❃❏✜✞▼❆✗❏✏✭■▲❜❄★❆✁✂✕❄✰❅❃❆ ✱✲❛ ❙ ✌☞✤ ✁ ❄✰❅
  • ■❅❑❏▼▲
✛ ❏✟✑✭❆❃❱✄❲❀❳✰❛❪❙ ✌☞✦ ✁ ❯ ❄✞❅✽✞✏☛ ❄✞❅✗❆❍❏☎☛❋●✧✌ ❙ ✍❘◗ ✁ ✶✛✚✢✓✭❆✗❏ ✂ ✁ ❱ ✠ ❆ ✁ ✄ ❲❜❄✰❅❃❆✬☛★❅ ❳✲✱✪✞✭❅✟✭✺❏✜☛ ❏ ✁ ✠ ✞✜☛✬✓ ❆❃❱ ✱ ❵ ❆✁✂✢❄☎✓ ✁ ❏☎☛ ❛ ❙ ✍❜❖ ✁ ❏✜☛✄❵✎❵❚❙ ✍✜✌ ✁ ❯✎❱✄❲❚❳✌❄✞❅✗❆ ❄✲●✎◗❚❙P❄✄❴✜✞ ❙❥❄✲❵❘❵✢❛ ✍✏✍ ✁ ✗ ✍☞✖ ✁ ❄✰❅ ✁ ✞✹✭✜✭☞✮✟☛❘❏ ✂ ❏★❅❃❆❚❳✿❅❑❏✲▲ ✄ ❅❃❆✗❏✏✸✗❏▼❲❚❳✌❄✺❵ ❏☎☛ ❛✎❛❪❙ ✍ ✙ ✁ ✵ ✍✏✚ ✁ ✵ ✍✏✣ ✁ ❅❇❆✳❈❊❉✪❋❍●❏■☞❑▼▲❖◆❊■☞❑✳❋❍●P❑✳❆✳❈❊❉◗■☞❑▼❑❃❈❙❘☎❋❯❚✢❱✿❲✺❈❨❳✲❳✲❳ ✂✁☎✄✝✆✞✄✠✟☛✡ ❣❩❡❍⑤✪♠①④❦⑤✥❧✞✈✠⑥
slide-87
SLIDE 87 ✂✁☎✄✝✆✞✄✠✟☛✡ ❣❩❡❍⑤✪♠①④❦⑤✥❧✞✈✠⑥ ✞ ⑧ ✂✁☎✄✝✆✟✞✡✠☞☛✍✌✏✎✒✑✓☛✍✌✔✞✡✠✕✌☎✁✔✄✗✖✒✘✙✘✙✘ ✍✏✤ ✁ ✄ ❲❃❱▼❆❃❏✬✑★❆❃❏☞✭❄✶✲❆✎❲❜❄✰❅✟✸ ✄ ❲❜❄✰❅❃❆✦✥❘❱✲❅✗❆❃❏✲❅✗❆✢✓ ❳✰❛ ✍✏✦ ✁ ✗ ✖✎◗ ✁ ❲✗❏✄❆ ✠ ❲✄❅ ❏✜☛❋❵✻✱✝✱ ❵✒❄✰❅ ✁ ❆❃❱☎✶✲❆✎❲❑❄✞❅✟✸ ❳✰❛❪❙ ✖✢❖ ✁ ✵ ✖☎✌ ✁ ✖✜✍ ✁ ✄ ❲❃❱▼❆❃❏✬✑★❆❃❏☞✭❄✶✲❆✎❲❜❄✰❅✟✸ ✄ ❲❜❄✰❅❃❆★✧✣✚ ✄ ❏ ❳✰❛ ✖✏✖ ✁ ✗ ✖ ✙ ✁ ❲✗❏✄❆ ✠ ❲✄❅❀✱ ✮✟☛✄❏ ✂ ❏★❅❃❆✏✴ ❄✞❅✆✂❑❏▼❲❜❄★❆✽✓ ❯✄❲❃❱ ✂ ✱ ❵✼✓ ✠ ✄ ❏▼❲ ✁ ✄ ❲❜❄✰❅❃❆✣✧★✚ ✄ ❏ ❳ ❛ ❙ ✖✜✚ ✁ ✵ ✖✜✣ ✁ ✖✜✤ ✁ ✄ ✠✜✎ ☛❃❄✏✑✷✶▼❆❘❲❜❄✞❅✬✸❋❆❃❱✜✶▼❆❘❲❜❄✞❅✬✸❀❳ ❛ ✖✜✦ ✁ ✗ ✙ ◗ ✁ ❲✗❏✄❆ ✠ ❲✄❅ ✄ ❲❜❄✰❅❃❆★✧✣✚ ✄ ❏ ❳✰❛ ❵ ✙ ❖ ✁ ✱❂✞★❅✟✭ ✑✲❱✲❅✗❆✟✞❃❄✰❅✳✓ ✱ ❵ ✄ ❲❜❄✞❅✗❆✦✥❘❱✲❅❃❆✗❏✲❅✗❆✢✓❪❳ ❛ ❙ ✙ ✌ ✁ ✵ ✙ ✍ ✁ ✙ ✄ ✴ ✜ ✁ t✢✂ ❦▼♥♣✈✠⑥⑦④❦❣❩♠✂♠①③✞✈✇❡❍❧✞♠❝✍❸❧✞♠✂❡❥❺❵♠①③⑦④❦♦ ✍⑦♥①❡❥②❥♥✙❤❥q❝⑧ ✙ ✴ ✜ ✁ ☞✁ ☛❿ ➃ ❞ ✂✁☎✄✝✆✞✄✠✟☛✡
slide-88
SLIDE 88