Object Oriented Sys..

plumponionchipsSoftware and s/w Development

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

76 views


1

Content


Introduction

................................
................................
................................
....................

2

Key Principles of Object Oriented Systems

................................
................................
...

3

Object

................................
................................
................................
.........................

3

Classes
................................
................................
................................
........................

3

Attribute

................................
................................
................................
.....................

4

Method

................................
................................
................................
.......................

4

Message
................................
................................
................................
......................

4

Abstraction

................................
................................
................................
.................

4

Encapsulation

................................
................................
................................
.............

5

Inher
itance
................................
................................
................................
..................

6

Polymorphism

................................
................................
................................
............

7

Discussion of Rationale

................................
................................
................................
.

8

Advantages and Disad
vantages

................................
................................
....................

10

Advantages

................................
................................
................................
...............

10

Disadvantages

................................
................................
................................
..........

10

References

................................
................................
................................
....................

12


2

Introduction



Object oriented system has been heralded as a silver bullet. It is an important
technology and has made an important contribution to the software engineering field.
There are a lot of programming languages today that can t
ake full advantages of
object oriented design. Microsoft’s latest language C# (which is recommended
language to use under .Net framework) is fully object oriented. Unlike Java, all
primitive data type (int, float, char, boolean and etc.) in C# are object.
This is
very
interesting to see.
As we all heard, “everything is an object” in Java, I think (just
my
opinion
)

that’s not exactly true. It may

be

true comparing with C++ because C++ has
“backward
-
compatibility” with C. It means that you could program non
object
-
oriented in C++ but not with Java or C#. However, this essay is not about comparing
object oriented programming languages or how “object oriented” xxx language is.


This essay is to describe the key principles of object oriented systems, the rationa
le
behind them and their advantages/disadvantages in comparison to non object

oriented
desing methodologies (though I’m not a theory guy, I’m more interested in practical
stuff and getting things done).

I am referring to Java as object oriented language an
d
C as structued or non
-
object oriented language, unless stated otherwise.


I might redescribe, modify or quote from various books, web sites and etc.

in order to
complete this essay. Please refer reference section for details.
I might
also
add my
own opin
ion about it, as much as I know or aware of.


3


Key Principles of Object Oriented Systems



Object

Object oriented system is all about object. Simply speaking, objects are things.
A real
-
world thing o
r an abstraction of that thing.


Pete Coad and Edward You
rdon defined object as
:

“A
n abstraction of something in a
problem domain, reflection the capabilities of the system to keep information about it,
interact with it, or both; an encapsulation of attributes values and their exclusive
services.



Don Firesmith

provides the following definition in his book: “An object is defined as
a software abstraction that models all the relavent aspects of a single tangible or
conceptual entity or thing from the application domain or solution space. An object is
one of the p
rimary software entities in an object
-
oriented application, typically
corresponds to a software module, and consists of a set of related attributes types,
attributes, messages, exception, operations, and option component object.”


Classes

An object is defi
ned via its
class.

A class is a collection of one or more objects with a
uniform set of attributes and services, including a description of how to create new
objects i
n the class. (
definition by
Edward Yourdon).


In Microsoft .Net Developer journal, classe
s are defined as “T
emplates used for
defining new types. Classes describe both the properties and behaviors of objects.
Properties contain the data that are exposed by the class. Behaviors are the
functionality of the object, and are defined by the public
methods (also called member
functions) and events of the class. Collectively, the public properties and methods of a
class are known as the object interface. Classes themselves are not objects, but instead
they are used to instantiate (i.e., create) object
s in memory.



4

Attribute

T
he data encapsulated by an object. The only data which should be declared as part of
an object's attributes is the data required to describe the object's state at any particular
time. For example, the attributes of a circle are it
s radius and the coordinates of its
center. The actual code for implementing circle objects might require other data items
for calculations, but these would not be considered part of the attributes for that
object.


Method

An operation defined for an objec
t, implemented as a procedure or function in a
programming language. The calling sequence for a method is called a method
signature. A call to a method is called a method invocation


Message


A communication from one object (the sender) to another (the rec
eiver) requesting it
perform a named action as specified by the selector, parameterised with a specified set
of arguments. The result of the method execution (an object in itself) is answered
(returned) to the sender.


Abstraction

A simplified representati
on of something that is potentially quite complex. It is often
not necessary to know the exact details of how something works, is represented or is
implemented, because we can still make use of it in its simplified form. Object
-
oriented design often involv
es finding the right level of abstraction at which to work
when modeling real
-
life objects. If the level is too high, then not enough detail will be
captured. If the level is too low, then a program could be more complex and difficult
to create and underst
and than it needs to be.


In the context of object oriented development, we design classes so that clients of a
class do not need to know about the detailed implementation of the class.

Perfect
supports this kind of abstraction in specifications as well as

implementations.
Although it is sometimes possible to define a class adequately by its behaviour alone,

5

more often it is necessary to have some model of the data stored by the class in order
to understand what the class is for. The class methods are speci
fied in terms of this
abstract data model (although naturally, clients of the class do not have direct access
to it). This leaves the way open to refining the abstract data model to a more efficient
implementation model.


Encapsulation

Any mechanism that a
llows us to “hide” the implementation of the object so that other
components of the system will not be aware of (or be able to take advantage of) the
“innards” of the data stored in the object. As a practical matter, this means that an
object’s data (or at
tributes) and the funtions that operate on the data (typically known
ass “methods”, “operations” or “services”) are packaged together.


Encapsulation enables objects to hide their implementation from other objects. A
principles called
information hiding.
A
lthough objects can communicate with one
another across well
-
defined interfaces (just like the driver’s interface to a car includes
a steering wheel, accelerator pedal, brake, pedal and gear shift), objects are unaware
of how other objects are implemented


just like the driver may be unaware of how
the steering , engine, brake and transmission mechanisms are implemented. Normally,
implementation details are hidden within the object themselves. Surely, it is possible
to drive a car effectively without knowi
ng the details of how engines, transmissons,
and exhaust systems work. Similarly, it is possible to select a radio station on a car
stereo without knowing how the radio works.


6

Inheritance

A mechanism for reusing code, by which each class inherits the meth
ods (and
optionally the data) of its superclass. By identifying where different types of objects
have common functionality, you can implement the common methods for that
functionality in a single class and inherit it in any number of subclasses. Each class

inherits all the methods of its superclass, so a class ultimately inherits all methods all
the way up to the root class (Base). A class object inherits the class methods of its
superclass, and an instance object inherits the instance methods of its superc
lass.


For example, have a look at the following diagram. This example is taken from Bruce
Eckel’s book,
Thinking in Java

(which I think it’s a great Java book). Class
Circle
,
Square
, and
Triangle

are inherited from class
Shape
.






The base

(or supercl
ass)

type is “shape,” and each shape has a size, a color, a position,
and so on. Each shape can be drawn, erased, moved, colored, etc. From this, specific
types of shapes are derived (inherited)

circle, square, triangle, and so on


each of
which may have
additional characteristics and behaviors. Certain shapes can be
flipped, for example. Some behaviors may be different, such as when you want to
calculate the area of a shape. The type hierarchy embodies both the similarities and
differences between the sha
pes
.


7

Polymorphism

The ability of an object reference to be used as if it referred to an object with different
forms. Polymorphism in Java results from both class inheritance and interface
inheritance.
Polymorphism allows improved code organization and rea
dability as well
as the creation of
extensible

programs that can be “grown” not only during the
original creation of the project, but also when new features are desired.


With polymorphism, it is possible to design and implement systems that are easily
ext
ensible. New classes can be added with little or no modification to the generic
portions of the program.


Java: How to Program
book by Deitel & Deitel (fifth edition) has a great Java code
example to demonstrate polymorphism. It’s kinda long to be put in h
ere. If you are
interested, please refer to page 449.



8

Discussion of Rationale



This section will be written according to my knowledge. W
h
ether it’s true or not, it’s
up to you to judge. It is an o
pinion. Afterall, I’ve been asked to write “Discussion of

Rationale”. So this is a discussion, which open to correctness and counter
-
arguments.
Hopefully I won’t be much out off track.


As we’ve seen on the previous pages, it’s easy to see why we should adopt object
oriented technology.

Intuitively, it’s because

the increased of productivity, rapid
systems development, increased quality and maintainbility. Advantages and
disadvantages are discussed explicitly in the next section.


So shall we kick C programming and adopt

object oriented languages such as

Java,
C#
, C++ altogether? The answer is (for me) no. I would argue, as simple as, you can’t
write everything in Java and/or

C#.
It’s suitable for desktop and business applications,
but not everything.
For example, you can’t write operating system with Java. Java
r
uns on virtual machine (rationale for this is, so it can be platform
-
independent), on
top of an operating system. When you compile a Java program, the compiler translate
the code into java byte codes, not machine languages. The java byte codes will be
then

executed by JVM (Java Virtual Machine) on top of an operating system. So, it’s
impossible to write a full blow operating system in Java. It would be like running an
operating system under another operating system. Same goes to C#. C# also runs on
virtual
machine called MVM (Microsoft Virtual Machine).


Ones might argue the above statement made by me by proposing C++ as alternative

(backward
-
compatibality with C, as I stated on my Introduction section)
. I would
argue back by quoting Linus T
or
vald
s
, the dev
eloper of Linux kernel

(I’m a Linux
user myself, I have Debian Linux installed on my PC)
. As we all know, Linux is
written using C. Here’s a snippet

of an interview

why he chooses C instead of object
oriented laguages C++:


The interviewer
: Many people ask

why the kernel is written in C instead of
C++. What is your point against using C++ in the kernel? What is the
language you like best, excluding C?


Linus
: C++ would have allowed us to use certain compiler features that I
would have liked, and it was in f
act used for a very short timeperiod just
before releasing Linux
-
1.0. It turned out to not be very useful, and I don't think
we'll ever end up trying that again, for a few reasons. One reason is that C++

9

simply is a lot more complicated, and the compiler o
ften does things behind
the back of the programmer that aren't at all obvious when looking at the code
locally. Yes, you can avoid features like virtual classes and avoid these things,
but the point is that C++ simply allows a lot that C doesn't allow, and

that can
make finding the problems later harder.


Another reason was related to the above, namely compiler speed and stability.
Because C++ is a more complex language, it also has a propensity for a lot
more compiler bugs and compiles are usually slower.

This can be considered a
compiler implementation issue, but the basic complexity of C++ certainly is
something that can be objectively considered to be harmful for kernel
development.



When asked about Java, here’s his opinion:


The Interviewer:
What do
you think of the Java phenomenon? Did you ever
consider integrating a Java VM, like kaffe, in the kernel?


Linus
: I've always felt that Java had a lot too much hype associated with it,
and that is still true. I hope sincerely that Java will succeed, but I'
m pragmatic
and I'm not going to jump on the Java bandwagon premat
urely.
Linux already
supports seamless running of Java applications as it is, and the fact that the
kernel only acts as a wrapper for the thing rather than trying to run the Java
VM directly

I consider to be only an advantage.


Full interview can be read at
http://www.linuxgazette.com/issue32/rubini.html



People who adopt Object Oriented Systems say that they’ve done so because

its
promote extensibility and maintainbility as opposed to C. But as we can see, Linux
*is* extensible and maintainable. If not, there will be no Redhat, Fedora, Debian,
Slackware, Gentoo and etc. It it’s not maintainable we won’t see Linux kernel
support
ing the latest hardware such SATA drive, Usb hot plugs and etc.


As a conclustion for this section, I’d say object oriented system design is not suitable
for everything, everytime, anywhere regardless what or how. It has its strenght and
weaknesses. We’ll
see the advantages and disadvantages in the next section.


So,

Object Oriented Systems is just another
fad du juour?


10

Advantages and Disadvantages


Advantages

One of the principal advantages of object
-
oriented programming
/systems

techniques
over procedura
l programming techniques is that they enable programmers to create
modules that do not need to be changed when a new type of object is added. A
programmer can simply create a new object that inherits many of its features from
existing objects. This makes o
bject
-
oriented programs easier to modify.


Other

advantages of

object oriented system

is
,

its ease of modification; objects can
easily be modified and added to a system there by reducing maintenance costs.


Object oriented

programming is also considered t
o be better at modeling the real
world than is procedural programming. It allows for more complicated and flexible
interactions.


O
bject oriented

systems are also easier for non
-
technical personnel to understand and
easier for them to participate in the ma
intenance and enhancement of a system
because it appeals to natural human cognition patterns.


For some systems, an
object oriented

approach can speed development time since
many objects are standard across systems and can be reused. Components that
manage

dates, shipping, shopping carts, etc. can be purchased and easily modified for
a specific system.


Disadvantages

One of the disadvantages of object
-
oriented
system

is that it can, and often does, mean
a more slowly performing application. Unfortunately, t
his has more to do with a lack
of care when designing objects than it does with a fundamental flaw in object
-
oriented
development
.


It
is also
requires right combination of training, skill, and experience to do things the
right way. This requires organisat
ional commitment to formal training in object
-
oriented analysis techniques



11

Although the main advantage of object
-
oriented technique is reuse, reuse is easiest
when part of the problem domain matches a previous problem. It best works when
used in new devel
opment. Hewlett
-
Packard tried to recapture the requirements of
legacy systems using Object
-
Oriented Analysis and suggest that the reusability can
only be accomplished when legacy systems are projected for future needs (
Mike Bray,
1997
).


Other disadvantage
s is it enforces the 'what' and the 'how' at the same time.


12

References


Books


Yourdon, Edward. (1994).
Object
-
Oriented Systems Design: An Intergrated
Approach.
Upper Saddle River: Prentice Hall.


Deitel, H. M., & P. J. Deitel. (2003).
Java: How To Progra
m
. New Jersey: Pearson
Education.


Eckel, Bruce (2003).
Thinking in Java
. Calirfornia: Mindview.



Websites


http://www.cs.ukc.ac.uk/people/staff/djb/book/glossary.html

http://www.eschertech.com/tutorial/glossary.htm

http://www.developer.com/net/net/articl
e.php/1756291

http://supportline.microfocus.com/documentation/books/oc41books/mxglos.htm

http://www.linuxgazette.com/issue32/rubini.html

http://www.object
-
arts.com/EducationCentre/Glossary.htm

http://nonstop.compaq.com/nsswdocs/corba/corba2
-
3B11/common/glo
s_def.htm

http://www.developer.com/tech/article.php/3333541

http://www.archwing.com/technet/technet_OO.html