23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

java.datastructures.net<br />

2.1 Goals, Pr<strong>in</strong>ciples, <strong>and</strong> Patterns<br />

As the name implies, the ma<strong>in</strong> "actors" <strong>in</strong> the object-oriented design paradigm are<br />

called objects. An object comes from a class, which is a specification of the data<br />

fields, also called <strong>in</strong>stance variables, that the object conta<strong>in</strong>s, as well as the methods<br />

(operations) that the object can execute. Each class presents to the outside world a<br />

concise <strong>and</strong> consistent view of the objects that are <strong>in</strong>stances of this class, without<br />

go<strong>in</strong>g <strong>in</strong>to too much unnecessary detail or giv<strong>in</strong>g others access to the <strong>in</strong>ner work<strong>in</strong>gs<br />

of the objects. This view of comput<strong>in</strong>g is <strong>in</strong>tended to fulfill several goals <strong>and</strong><br />

<strong>in</strong>corporate several design pr<strong>in</strong>ciples, which we discuss <strong>in</strong> this chapter.<br />

2.1.1 Object-Oriented Design Goals<br />

Software implementations should achieve robustness, adaptability, <strong>and</strong> reusability.<br />

(See Figure 2.1.)<br />

Figure 2.1: Goals of object-oriented design.<br />

Robustness<br />

Every good programmer wants to develop software that is correct, which means<br />

that a program produces the right output for all the anticipated <strong>in</strong>puts <strong>in</strong> the<br />

program's application. In addition, we want software to be robust, that is, capable<br />

of h<strong>and</strong>l<strong>in</strong>g unexpected <strong>in</strong>puts that are not explicitly def<strong>in</strong>ed for its application.<br />

For example, if a program is expect<strong>in</strong>g a positive <strong>in</strong>teger (for example,<br />

represent<strong>in</strong>g the price of an item) <strong>and</strong> <strong>in</strong>stead is given a negative <strong>in</strong>teger, then the<br />

program should be able to recover gracefully from this error. More importantly, <strong>in</strong><br />

life-critical applications, where a software error can lead to <strong>in</strong>jury or loss of life,<br />

software that is not robust could be deadly. This po<strong>in</strong>t was driven home <strong>in</strong> the late<br />

1980s <strong>in</strong> accidents <strong>in</strong>volv<strong>in</strong>g Therac-25, a radiation-therapy mach<strong>in</strong>e, which<br />

91

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

Saved successfully!

Ooh no, something went wrong!