Introduction to the C Programming Language - Applied Research Lab

processroguishSoftware and s/w Development

Nov 18, 2013 (3 years and 10 months ago)

95 views

Washington

WASHINGTON UNIVERSITY IN ST LOUIS

Object
-
Oriented Design

Fred Kuhns

fredk@cse.wustl.edu

Applied Research Laboratory,

Department of Computer Science and Engineering,

Washington University in St. Louis

2

Fred Kuhns (
11/18/2013
)

CS422


Operating Systems Concepts

The Object Model


Software system are inherently complex: problem
domain, development process, maintenance or just
clearly articulating the system’s requirements (there
are endless possibilities)



Manage complexity by Decomposing system into
smaller, independent components
.



Components, in turn, are composed of one or more
objects



Abstraction

and
hierarchy

play fundamental roles


3

Fred Kuhns (
11/18/2013
)

CS422


Operating Systems Concepts

Fundamentals: Booch, “OOA&D”


Object
-
oriented Analysis (OOA)

“Object
-
oriented analysis is a method of analysis that examines
requirements from the perspective of the classes and objects
found in the vocabulary”



Object
-
oriented Design (OOD)

“Object
-
oriented design is a method of design encompassing the
process of object
-
oriented decomposition and a notation for
depicting both logical and physical as well as static and dynamic
models of the system under design”



Object
-
oriented Programming (OOP)

“Object
-
oriented programming is a method of implementation in
which programs are organized as cooperative collections of
objects, each of which represents an instance of some class, and
whose classes are all members of a hierarchy of classes united via
inheritance relationships”


4

Fred Kuhns (
11/18/2013
)

CS422


Operating Systems Concepts

Major elements of the Object Model


Abstraction
: essential characteristics of an object,
that is its behavior or semantics. Separate behavior
from implementation.


Kinds

of abstractions:
Entity
,
Action
,
Virtual machine

and
Coincidental
.


Contract model
: interface defines contract between (server) and
user (client): it defines the objects
responsibilities
.


Invariants
: each operation associated with an object may have a
set of
preconditions

(required invariants before invocation) and
post conditions

(invariants satisfied by operation).

Exceptions indicate an invariant is not satisfied.


static

and
dynamic

properties


may be
active

or
passive
. Active objects may use
callback

mechanism to notify client of an event.

5

Fred Kuhns (
11/18/2013
)

CS422


Operating Systems Concepts

Major elements of the Object Model


Encapsulation


Implementation of abstraction


Object abstraction should precede implementation decisions.
Implementation is not visible external to object and so
implementation may change of time with no impact to clients.


Separation of concerns
: one level of abstraction should not be
concerned with another's implementation.


Keep implementation a
secret


Attempt to localize aspects of an object that may change


Modularity


Design partitioned into a set of components with well defined
interfaces.


Group logically related classes



Modularity is the property of a system that has been
decomposed into a set of cohesive and loosely coupled modules
”,
G. Booch

6

Fred Kuhns (
11/18/2013
)

CS422


Operating Systems Concepts

Major elements of the Object Model


Hierarchy


“Hierarchy is a ranking or ordering of abstractions”, G. Booch


Class hierarchy defines “
is
-
a
” relationships (
inheritance
)


Important to guard against violating encapsulation (Liskov).
Control in C++ using
public
,
protected

and
private


single versus multiple inheritance


see class notes


Containment defines “
has
-
a
” relationships. A classes behavior
is defined by an other objects.


7

Fred Kuhns (
11/18/2013
)

CS422


Operating Systems Concepts

3 Stages of Developing Software


Analysis
: identify problem to be solved and define scope.


This is a critical step, vague or contradictory requirements are defined
then the result in software which will likely not satisfy clients.


Vague requirements must be refined


Assumptions must be stated


Design


Decompose system into a set of reasonably independent modules (loosely
coupled).


Use abstraction, encapsulation and hierarchy to manage complexity


Implementation


Clarify class roles and relationships


Implementation strategy for selected language


Test, verify, simplify


Revisit all 3 steps


Each step will likely require experimentation, testing, analysis,
documentation and refinements.

8

Fred Kuhns (
11/18/2013
)

CS422


Operating Systems Concepts

Goals and Quality Metrics


Assume a selfish model:


Your time is valuable
: minimize required coding, coordination,
documentation and justifications. Code
reuse
, simple
implementations,
modular
.


Quality of product reflects on you
: meet requirements, bugs,
undocumented “features”, performance, efficiency.

Test
,
verify

and
Characterize
.


Avoid late nights at the keyboard
:
clear
,
simple

and
efficient

interfaces are unlikely to be abused, misused or broken by
yourself or others.
Write code once



if you find yourself
repeating the same code then isolate it in a class or method.
Write
flexible
,
portable

code.


Minimize frustration when changes are required
: ensure
classes/components are
extensible

with minimal effort. When
changes are required try to keep it localized.