29.11.2014 Views

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

In time most developers start to actively look to see where they c<strong>an</strong> restructure classes to<br />

improve the potential for reuse. As long as this is not taken too far, this is <strong>an</strong> extremely healthy<br />

thing to do.<br />

Data protection for little effort . Due to the encapsulation facilities provided as part of the l<strong>an</strong>guage<br />

you get your data protected from unscrupulous users. Unlike l<strong>an</strong>guages such as Ada, you don’t<br />

have to write reams of specification in order to achieve this protection.<br />

Encapsulation eases integratio n. As users of <strong>an</strong> object c<strong>an</strong>not access the internals of the object they<br />

must go via specified interfaces. As these interfaces c<strong>an</strong> be published in adv<strong>an</strong>ce of the object<br />

being implemented, others c<strong>an</strong> develop to those interfaces knowing that they will be avai lable<br />

when the object is implemented.<br />

Encapsulation eases mainten<strong>an</strong>ce . This point is really a variation on the last point. As users of <strong>an</strong><br />

object have been forced to access the object via the specified interfaces, as long as the external<br />

behavior of these o bjects appears to remain the same, the internals of the object c<strong>an</strong> be<br />

completely ch<strong>an</strong>ged. For example, <strong>an</strong> object could store <strong>an</strong> item of data in a flat file, read it<br />

from a sensor or obtain it from a database. However, external uses of the object need never<br />

know.<br />

Simplified code - polymorphism . With polymorphism you don’t need to worry about exactly what<br />

type of object you will get at run time, only that it must respond to the message (request for a<br />

method to be executed) you send it. This me<strong>an</strong>s that it is a great deal easier to write reusable,<br />

compact code, th<strong>an</strong> in m<strong>an</strong>y other l<strong>an</strong>guages.<br />

More intuitive programming paradigm . It has been argued that object orientation is a more intuitive<br />

programming paradigm th<strong>an</strong> approaches such as procedural. This is because w e hum<strong>an</strong>s tend<br />

to perceive the world in terms of objects. We see dials, windows, switches, fuel pumps,<br />

automated teller machines (ATMs). These objects respond to our use in specific ways when we<br />

interact with them. For example, <strong>an</strong> ATM will require a card, a PIN number etc. in a particular<br />

sequence. Of course those of us who have programmed before bring with us a lot of baggage<br />

including preconceptions of what a program should be like <strong><strong>an</strong>d</strong> how you develop one.<br />

Hopefully, this book is about to turn all that on its head for a while, before putting everything<br />

back together again.<br />

2.4.3 What are the problems/pitfalls?<br />

Of course no programming l<strong>an</strong>guage / paradigm is without its own set of problems <strong><strong>an</strong>d</strong> pitfalls. Indeed<br />

part of the skill in becoming fluent in a new programm ing l<strong>an</strong>guage is learning what the problems are<br />

<strong><strong>an</strong>d</strong> how to avoid them. In this section we will concentrate on the damning statements usually leveled at<br />

object orientation. We will deal with common software problems in a later chapter.<br />

2.4.3.1 Lots of confusing terminology<br />

This is actually a fair comment. As you have already seen, object orientation is littered with new terms<br />

<strong><strong>an</strong>d</strong> definitions for what appears to have already been defined quite acceptably in other l<strong>an</strong>guages. It is<br />

difficult to argue against this <strong><strong>an</strong>d</strong> o ne may ask the question why this is the case? Certainly, back in the<br />

early 70s when <strong>Smalltalk</strong> was being researched, m<strong>an</strong>y of the terms we now take for gr<strong>an</strong>ted were<br />

already quite well established. It would be unreasonable to assume that even if the inventors of the<br />

l<strong>an</strong>guage like their own terminology early users would have tried to get the terminology ch<strong>an</strong>ged.<br />

One possible <strong>an</strong>swer to this is that in the past (that is, during the early <strong><strong>an</strong>d</strong> mid eighties) object<br />

oriented l<strong>an</strong>guages, such as <strong>Smalltalk</strong>, tended to be the preserve of academics <strong><strong>an</strong>d</strong> research institutions.<br />

(Indeed I myself was introduced to it while working on a research project at a British university during<br />

1986/87 having worked with Lisp Flavors for a few years). It is often the case that these people enjoy<br />

the mystique that a l<strong>an</strong>guage with terminology all of its own c<strong>an</strong> create. By now it is so well established<br />

in the object oriented culture that you as a new comer will just have to adapt. The import<strong>an</strong>t point to<br />

remember is that the concepts are actually very simple, although the practice c<strong>an</strong> be harder. To illustrate<br />

this, consider the following table, this attempts to illustrate the parallels between object oriented<br />

terminology <strong><strong>an</strong>d</strong> procedural terminology:<br />

These approximations should not be taken too li terally as they are intended only to help you<br />

visualize what each of the terms me<strong>an</strong>s. Hopefully, by the end of the book you will have gained your<br />

own underst<strong><strong>an</strong>d</strong>ing of their me<strong>an</strong>ing.<br />

30

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!