•Decomposition & Abstraction
-Abstraction by paramerization is taken for granted
-Abstraction by specification deals with precondition & postcondition
•Kinds of Abstraction
•procedural abstraction – ops
return_type method(…)
//REQUIRES:
//MODIFIES:
//EFFECTS:
//EXCEPTIONS:
•data abstraction – data types
-To delay defining structure
-To allow implementation changes
//OVERVIEW:
//CONSTRUCTORS:
//METHODS:
-A data abstraction is mutable if it has any mutator methods
-There are four kinds of ops provided by data abstraction
1)creators(constructors) produce new objects from scratch
2)producers produce new objects given existing objects as arguments
3)mutators modify state of objects
4)observers provide info on states
-Mutable objects are equal only if they are the same object –> no need to implement equals()
-Immutable objects are equal if they have the same state –> must implement their own equals() meth
-If two objects are equivalent according to equals(), hashCode() should produce same value to them –> must implement for types intended to be keys in hash tables
-clone() should return an object that has the same state. Immutable types can inherit clone() but mutable should implement it themselves
-toString() should return a string showing the type and current state of its object. All types must implement toString() themselves
-iteration abstraction
-type hierarchy
•Type Hierarchy
-Compiler ensures the apperent type it deduces from an object is always a supertype of the actual type of the object
-Compiler determines which calls are legal based on object’s apperent type
-Dispatching causes method calls to go to the object’s actual code
-Subclass method can throw fewer exception types.
-Var or method must be declared protected in order to be accessed by its subclass but generally should be avoided so that superclass can be reimplemented and avoid its access by other classes in the pkg
-Abstract class may contain >= 1 variables. If it does, it will also have one or more constructors to initialize the variables. These constructors can not be called by users since an abstract class has no objects.
•Testing and Debugging
-Testing is the process of executing a program on a set of test cases and comparing actual results with the expected ones.
-Debugging pinpoints location of errors
•Design
°Design Goals
Meet fxnal and performance reqs
Define a modular structurs such that
-Components are good abstractions
-Structure is simple, easy to implement and modify
°Design Process
-Select a target abstraction whose impl has not yet been studied
-Identify helper abstractions
-Sketch how helper will be used
-Iterate over all abstractions
°Design Notebook
-Module dependency diagram
-A section for each abstraction containing:
Spec
Performance req
A sketch of its impl
Other info