Download presentation
Presentation is loading. Please wait.
1
Object Oriented Design & Packages CSC 171 FALL 2001 LECTURE 13
2
History: von Neumann Machines 30 June 1945: John von Neumann wrote the "First Draft of a Report on the EDVAC“ – Never got past draft stage – No co-authors ever named Set the stage for the architectural design of several generations of computers The architectural style became known as the "von Neumann architecture" Source of the concept of the "stored program" becomes a matter of controversy. Eckert and Mauchly claimed that they had those thoughts before von Neumann joined the U of Penn. Konrad Zuse clamed that he had those thoughts in the 1930's
3
von Neumann Architecture Dual usage of main memory to store both program instructions and data FETCH-DECODE-EXECUTE cycle – Fetch an instruction from memory – Decode the instruction Operation (OP-CODE) Operand (data portion – constant, memory loc, pointer) – Execute operation on operand – Increment program counter and repeat
4
Software Lifecycle
5
Waterfall Model with Iterative Feedback
6
Forward looking Iterative Waterfall Model
8
Programming by Contract Problem: – Class descriptions are often vague – Example: “I want you to write a ‘Drawingtool’ class for a graphics applet. It only moves forward, but it can change direction – draw or not draw.” One widely accepted solution is – Class specifications
9
Class specifications A Class Invariant Precondition/postcondition specifications for each method An optional modifies clause for each method
10
Class Invariant A collection of facts that are always true about class objects Example: a “DrawingTool” – Appears as an arrow within the DrawingCanvas window – Is either up, down, left, or write – Is either in drawing mode or in moving mode
11
The Precondition/Postcondition Contract IF The calling code ensures the precondition is true at the time it calls the method THEN The postcontion is guaranteed to be true at the time the method completes exectuion
12
Pre/Post conditions – Constructor public DrawingTool() Postconditions – A new DrawingTool object is created and placed in the center of the DrawingCanvas window – The object is set to drawing mode – The arrow for this object is pointing up – The DrawingTool arrow is colored Green
13
Pre/Post conditions – Updates Every non-constructor method has an implicit precondition: that the object is not null public turnClockwise() Postconditions – The object is rotated by 90 degrees clockwise from its previous direction
14
Pre/Post conditions – Updates public draw() Postconditions – The object is set to drawing mode – The DrawingTool arrow is colored Green public dontdraw() Postconditions – The object is set to moving mode – The DrawingTool arrow is colored Red
15
Pre/Post conditions – Updates public moveForward() Preconditions – A minimum of 20 pixels remain in front of the DrawingTool arrow before and edge of the DrawingCanvas window Postconditions – This DrawingTool object is moved in the arrow’s direction by 20 pixels from its previous location – If this object is in drawing mode, a line segment is drawn across the 20 pixel path just traversed
16
Good Class Specifications Precise Concise Sufficiently complete Accurate with respect to intended behavior
17
Packages java.swing java.awt. java.applet java.util java.lang java.io java.net Java provides tools to permit programmers to build their own packages
18
Package Declaration package identifier ; package identifier.identifier ; package identifier.identifier.identifier ; Etc....
19
Example 3 source files: package money; public class Euro { } package money; public class Dollar { } package money; public class Yen { } All in one directory
20
Directory Structure Before compile MoneyPackage – Dollar.java – Euro.java – Yen.java After compile MoneyPackage – Dollar.java – Euro.java – Yen.java – money Dollar.class Euro.class Yen.class
21
Using Packages import identifier ; import identifier.identifier ; import identifier.identifier.identifier ; import identifier.* ; Etc....
22
Accessing Packages WIN C:\autoexec.bat Set CLASSPATH =.;C:\MoneyPackage UNIX – C shell.login Setenv CLASSPATH.:/MoneyPackage UNIX – Korn shell.profile CLASSPATH=.:/MoneyPackage Export CLASSPATH
23
Using Package import identifier
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.