INTRODUCTORY OBJECT-ORIENTED CONCEPTS

glintplainvilleΛογισμικό & κατασκευή λογ/κού

18 Νοε 2013 (πριν από 3 χρόνια και 7 μήνες)

53 εμφανίσεις

OBJECT
-
ORIENTED CONCEPTS


What is an object?



"An object is a software entity that mirrors the real world in some way. A
software object in OOP has data (the attributes) and code that responds to
instructions. Think of the code and data as being welded

together
--
the code
completely wrapping the data in a shell to protect it from the hostile outside
world." [Franz]


”An object has state, behavior, and identity; [Booch 91]


“An object is an encapsulation of state (data values) and behavior
(operations).

Thus an object is in many ways similar to a module, or an
abstract data type." [Budd]


What are the differences between procedural languages and object
-
oriented
languages?



Procedural languages (Pascal, C, Fortran, etc.) operate on data a step at a
tim
e. A program written in one of these languages has two components:
data (variables and records) and code (instructions that act on the data and
do the work). There is a rigid separation of code from data.


An object
-
oriented language breaks a program in
to hundreds of tiny entities
that have small bits of code and data fused tightly together. Where
subroutines are a convenience in a procedural language, the separateness of
these entities is essential to an object
-
oriented program.


OBJECT
-
ORIENTATION IS
A NEW PARADIGM


Object
-
oriented programming is a new programming paradigm (a new way
of viewing the world).


The underlying ideas of the object
-
oriented technique are the same basic
methods humans use to solve problems in the world (e.g., abstraction).


Computer novices and children grasp the ideas of OOP easier than computer
professionals. The professionals require a paradigm shift which is very
difficult (due to preconceived notions) whereas the children don't.

TERMS:


1.
O
bject
: A software entity
that mirrors the real world in some way.
Everything in an object
-
oriented programming language is an object.


2.
Class
:

A class is a template from which objects are created (i.e., a
blueprint for the objects it defines). Every object made from a clas
s is the
same as every other.


3.
Instance
:

Instances are the individual objects created by a class. Every
object is an instance of a class.


Related Term:

Instantiation
:
Creating a new (specific) object from a general class is
called instantiation
.


4.
Method
:

The behavior of a class, and all its instances, is described by a
method.



Methods are like procedures:



they execute step
-
by
-
step,



can do branching and looping,



take arguments,



have local variables,



and return values (ob
jects).



Methods are unlike procedures:


they may only access data of the class for which they are
defined, an instance's data can only be accessed through

its
class' method.


Note: A class' methods completely encapsulate the data of objects of the
class for which they are defined.


5.
Message
:

A request to a specific instance, called the receiver, to invoke
a specific method. Along with the name of the method, (the selector)
additional information (arguments, i.e., objects) can be passed as part
of the
message.


When the object receives the message, it invokes the method for the selector.
This can:



(1) change the object's instance variables,



(2) send another object back as a direct response to the message,


(3) do something in the real wo
rld of the computer, such as display
information, print a message, or read a block of data from a file.


Much of the code within methods consists of passing messages to other
objects.



5.
Abstraction:

A problem solving tool that allows one to think of

a
problem at a higher level without worrying about the details. Abstraction
refers to organizing information based on
classification, generalization
,

and
aggregation
.


i.
Classification

forms new objects by suppressing the details of
individual instanc
es and emphasizing properties of the whole.
New object types (classes) are formed by collecting instances.



Classification

= set theoretic operation
'membership'


==> describes the
'instance
-
of'

relationship


EX:
Classification

would allow one to coll
ect the instances '{Jane, Bob,
Sue}' into a new higher
-
order type called 'secretary.'


ii.
Generalization

merges existing types to form new types.
Individual differences between subtypes are ignored and
common traits are emphasized.



Generalization

=
set theoretic operation 'union'


==>

describes the
'is
-
a'

relationship


EX: Existing employee types '{secretary, teacher}' can be generalized to
form the new type employee'.


Generalization

implies that every instance of the subtype is an instance
of
the type. Every instance of 'teacher' is also an instance of 'employee.'


iii.
Aggregation

forms an object as a relationship among other
objects. It suppresses the details of the components and
emphasizes the details of the relationship as a whole.



Aggregation

= set theoretic operation
'cartesian

product'


==> describes the
'is
-
part
-
of'

relationship


EX: Consider object types 'stove', 'refrigerator', 'sink', 'cabinet'. A 'kitchen'
object can be abstracted from the given objects. The individual

objects (e.g.,
'stove') are components of the aggregate ('kitchen'). An instance of a
component is said to be an attribute of an instance of the aggregate.


Classification, generalization
,
and
aggregation

are the basic ways we have
of structuring infor
mation. When they are repeatedly applied to objects,
hierarchies of new objects are formed.


6.
Information hiding

as defined by Parnas [Par72] suggests decomposing
systems into components that hide or encapsulate design decisions about
abstractions.


7.
Data abstraction

refers to defining data types in terms of the operations
that apply to objects of the type, with the constraint that the values of such
objects can be modified and observed only by the use of the operations
[Oxf86].



Data abstractio
n

is thinking in terms of what you can do to a
collection of data independently of how you do it.


Related term:


i.
Abstract data type

(ADT)

is a collection of data structured in a
particular fashion together with a set of operations that manipulate
th
e data.


8.
Inheritance:

The principle of receiving properties or characteristics from
an ancestor and is used to define new data types as extensions or restrictions
of existing types.


9.
Polymorphism and dynamic binding
:

Program entities should be
per
mitted to refer to objects of more than one class, and operations should be
permitted to have different realizations in different classes.



Polymorphism
:

refers to the situation whereby a given program
entity may refer at run
-
time to instances of diffe
rent classes.



Dynamic binding
:

refers to the situation whereby the run
-
time
system will automatically select the version of an operation adapted to
the corresponding instance.


10.
Multiple and repeated inheritance
:

It should be possible to declare
a
class as heir to more than one class, and more than once to the same class.