Академический Документы
Профессиональный Документы
Культура Документы
Basic OO Terms
Objects
Classes
Class attributes
Relationships
Methods (Services)
Encapsulation
Polymorhpism
Inheritance
Reuse
Objects and Classes
Object
An abstract or concrete thing, an entity
Each object instance must have a unique ID
Attribute
A property of an object
Classes
A groups of similar objects
Have the same kind of attributes
Example Class
The Class of Automobile Objects
Attritubtes
Vehicle Identification Number
Manufacturer
Color
Type (sedan, roadster, pickup, etc)
Price
Etc
Example Object Instances
Color Delete
Type
Price
Encapsulation
Attributes and methods are packaged
together.
Information hiding
Internal aspects are concealed or hidden.
Objects are prevented from changing other
objects.
Message Passing
User and other objects send messages to
objects.
Objects can be told to perform a service
(method).
Can be told to change itself.
May result from
Clicking a button,
Choosing from a list, etc.
Calling a method
Polymorhpism
Methods with the same name may do
different things.
Depends on the object class they are
associated with.
Accounting example:
Real Property and Computer Equipment are two
asset classes.
Both have Methods called Calculate Depreciation.
Real Property is depreciated on a straight-line basis
Computer equipment uses sum of the years digits.
Hierarchies and Inheritance
Classes arranged in hierarchies of sub-
classes and super-classes
Attributes and methods are inherited by
sub-classes
Inherited properties may be over-ridden.
Automobile Class Hierarchy
Motor Vehicles
# of Wheels
Engine
Assets Liabilities
Depreciation Method
Buildings Computers
Depreciation Depreciation
(Straight line) (Accelerated)
Insurance Policy Object
Attributes:
Policy Number
Policy Type
Owner
Premium
Method:
Calculate Penalty
Attribute Inheritance
Insurance Policies
Flood Plain
Earthquake
Date built
Feet from source Inherited Date built
Surveyor Building material
Last quake date
These mehtods
are inherited
Home Calculate age
Flood Plain
Earthquake
Calculate age
Calculate penalty Calculate age
Calculate penalty
Flood Plain
Earthquake
Calculate penalty
(100/Feet to source) Calculate penalty
* Appraised Value * .1 $0.50 * (Days
since last quake)
Polymorphism
Insurance Policies
Home
Calculate penalty message
Flood Plain
Earthquake
Calculate penalty
(100/Feet to source) Calculate penalty
* Appraised Value * .1 $0.50 * (Days
since last quake)
Benefits
Encapsulation provides data independence.
e.g., change an from integer to decimal type
without affecting other objects.
Inheritance provides a parsimonious environment.
Polymorphism allows applications to be generic,
removing the need for handling "special cases"
with Case statements of Ifs.
Objects can be placed in a library for reuse.
Summary
Objects entities
Classes groups of similar objects
Class attributes properties
Relationships associations, part-whole
Methods (Services) procedures
Encapsulation data hiding
Polymorhpism same method name,different proc.
Inheritance properties passed to children
Reuse object libraries