Title: Object-Oriented Principles and Implementations
1Object-Oriented Principles and Implementations
2Agenda
- Evolution of software
- OO software elements
- Object instantiation
- Run-time environment
- Mapping to real-world
- Object lifecycle
3Evolution of Software
- Remember form, function, style
- data, logic, paradigm
- state, behavior, style
- state collection of all data values (e.g., at
this time) - Paradigms
- monolithic
- modular
- functional gt ADTs gt OO gt componentware??
4OO Software Elements Objects
- real life view
- person, place, thing, concept, event
- OO view instantiation of a class
- storage view
- area of storage allocated to hold both the data
for this object and its superclasses (its
state), including all hidden data, and
references to executable code the object can
invoke/call - multiple objects of same class share executable
code and static variables
5OO Software Elements Classes
- real life view
- template, factory, pattern, IRS tax form
- OO view
- abstraction of a kind of object
- definition of services (methods) that can be
performed - storage view
- one copy of all static variables per class, plus
the storage to hold one copy of all method code,
plus some overhead - no storage for object/instance state
6Local Object Instantiation
- two storage areas
- local reference to object
- local storage for objects state and methods
- new is normally used
- allocates local memory
- object storage is released when
- object is no longer in use and garbage collector
runs - program exits
7Local Object Storage
- Declaration Temperature outside_temp
outside_temp (2AF0)
(object reference is null)
- Storage allocation
- outside_temp new Temperature(32.0)
2AF0
3C320
3C328
3C32C
3C330
8Two Local Objects of Same Class
Temperature outside_temp
new Temperature(32.0)
Temperature water_temp
new Temperature(212.0)
2AF0
3C320
3C328
2AF4
3C32C
3C330
3C340
3C348
3C34C
3C350
9Shallow Object Copy
Temperature outside_temp
new Temperature(32.0)
Temperature water_temp
new Temperature(212.0)
Temperature a_temp
outside_temp
2AF0
3C320
3C328
2AF4
3C32C
2AF8
3C330
3C340
3C348
3C34C
3C350
10Remote Object Instantiation
- four storage areas
- local reference to object (actually, for
stub/proxy) - local storage for proxy and parameters
- remote storage for remote proxy, parameters and
return value/exception info - remote storage for objects state and methods
- new is not used
- remote proxy causes new for remote object
- foundation for most of EA infrastructure
11Run-Time Environment
- loads/unloads classes
- schedules threads
- allocates storage
- runs garbage collection
- interfaces with operating system
12Mapping to Real World
- enabled by from exposed state to exposed
interface - handling large problems desirable
characteristics - object-orientations part in solving problems
13Desirable CharacteristicsModularity
- isolates functionality
- serves as unit of decomposition
- can be assigned as a work item
- allows for a standard interface
- speeds time to market by aiding problem
partitioning - helps with understandability
- thus maintainability and extensibility
14Desirable CharacteristicsEncapsulation
- simplifies interface
- promotes consistency
- controls access
- allows underlying data representation to change
- aids maintainability
15Desirable CharacteristicsAbstraction
- allows easier identification of reusable parts
- saves work effort by closer mapping to problem
- improves reliability by supporting reuse
- makes changes easier to propagate
- central, inherited concepts
- saves development time by inheriting capability
16Desirable CharacteristicsReuse
- saves time
- allows for purchase vs. roll-your-own
- allows reaping benefits of accumulated experience
from reused entity
17Object Orientation and the Real World
- Classes are generalizations and abstractions of
real-world objects and their behaviors - examples business concepts (Order), people
(User), service provider (DatabaseInterface) - Objects are unique and have an identity
- examples
- order451 (instance of Order)
- SaleClerkJane Doe (instance of User)
- inventory_db (instance of DatabaseInterface)
18Bean Object Activation Activities
- creation
- create bean object but defer assigning storage
for state - passivation
- disassociate bean object from its state and save
the state - removes bean object from memory
- activation
- loads bean object into memory
- restores state and associates with bean object
- removal
- remove bean object from memory