Lloseng CH 02
Lloseng CH 02
Chapter 2:
Review of Object Orientation
2.1 What is Object Orientation?
Procedural paradigm:
• Software is organized around the notion of procedures
• Procedural abstraction
—Works as long as the data is simple
• Adding data abstractions
—Groups together the pieces of data that describe
some entity
—Helps reduce the system’s complexity.
- Such as Records and structures
main
Account
credit
perform transaction debit
• Has properties
—Represent its state
• Has behaviour
—How it acts and reacts
—May simulate the behaviour of an object in the real
world
Margaret:
date of birth: 1980/03/03
Mortgage Account 29865: address: 150 C++ Rd.
position: Teller
balance: 198760.00
opened: 2000/08/12
property: 75 Object Dr. Transaction 487:
amount: 200.00
time: 2001/09/01 14:30
Instant Teller 876:
location: Java Valley Cafe
• Attributes
—Simple data
—E.g. name, dateOfBirth
• Associations
—Relationships to other important classes
—E.g. supervisor, coursesTaken
—More on these in Chapter 5
Type of a variable
• Determines what classes of objects it may contain
Inheritance hierarchies
• Show the relationships among superclasses and
subclasses
• A triangle shows a generalization
Inheritance
• The implicit possession by all subclasses of features
defined in its superclasses
Inheritance
• The implicit possession by all subclasses of features
defined in its superclasses
Shape2D Shape3D
Circle Quadrilateral
Rectangle
credit
debit
calculateInterest
2.6 Inheritance,
center
translate
getCenter
Polymorphism and
rotate
changeScale
getArea
Variables
getPerimeterLength
getBoundingRect
EllipticalShape Polygon
semiMajorAxis getBoundingRect
getVertices
Circle Ellipse
SimplePolygon ArbitraryPolygon
rotate semiMinorAxis
orientation orientation points
changeScale
getArea rotate addPoint
rotate getOrientation removePoint
getPerimeterLength changeScale
getBoundingRect rotate
getArea
getRadius changeScale
getPerimeterLength
getArea
getBoundingRect
Rectangle RegularPolygon getPerimeterLength
getOrientation
getVertices
getSemiMajorAxis height numPoints
getSemiMinorAxis width radius
getFocus1
changeScale changeNumPoints
getFocus2
setHeight changeScale
setWidth getArea
getArea getPerimeterLength
getPerimeterLength getVertices
getVertices
getBoundingRect
Original objects
(showing bounding rectangle)
Rotated objects
(showing bounding rectangle)
Translated objects
(showing original)
Scaled objects
(50%)
Scaled objects
(150%)
Iterator i = v.iterator();
while(i.hasNext())
{
aMethod(v.next());
}