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.

Abstraction<br />

The notion of abstraction is to distill a complicated system down to its most<br />

fundamental parts <strong>and</strong> describe these parts <strong>in</strong> a simple, precise language.<br />

Typically, describ<strong>in</strong>g the parts of a system <strong>in</strong>volves nam<strong>in</strong>g them <strong>and</strong> expla<strong>in</strong><strong>in</strong>g<br />

their functionality. Apply<strong>in</strong>g the abstraction paradigm to the design of data<br />

structures gives rise to abstract data types (ADTs). An ADT is a mathematical<br />

model of a data structure that specifies the type of data stored, the operations<br />

supported on them, <strong>and</strong> the types of parameters of the operations. An ADT<br />

specifies what each operation does, but not how it does it. In <strong>Java</strong>, an ADT can be<br />

expressed by an <strong>in</strong>terface, which is simply a list of method declarations, where<br />

each method has an empty body. (We say more about <strong>Java</strong> <strong>in</strong>terfaces <strong>in</strong> Section<br />

2.4.)<br />

An ADT is realized by a concrete data structure, which is modeled <strong>in</strong> <strong>Java</strong> by a<br />

class. A class def<strong>in</strong>es the data be<strong>in</strong>g stored <strong>and</strong> the operations supported by the<br />

objects that are <strong>in</strong>stances of the class. Also, unlike <strong>in</strong>terfaces, classes specify how<br />

the operations are performed <strong>in</strong> the body of each method. A <strong>Java</strong> class is said to<br />

implement an <strong>in</strong>terface if its methods <strong>in</strong>clude all the methods declared <strong>in</strong> the<br />

<strong>in</strong>terface, thus provid<strong>in</strong>g a body for them. However, a class can have more<br />

methods than those of the <strong>in</strong>terface.<br />

Encapsulation<br />

Another important pr<strong>in</strong>ciple of object-oriented design is the concept of<br />

encapsulation, which states that different components of a software system<br />

should not reveal the <strong>in</strong>ternal details of their respective implementations. One of<br />

the ma<strong>in</strong> advantages of encapsulation is that it gives the programmer freedom <strong>in</strong><br />

implement<strong>in</strong>g the details of a system. The only constra<strong>in</strong>t on the programmer is to<br />

ma<strong>in</strong>ta<strong>in</strong> the abstract <strong>in</strong>terface that outsiders see.<br />

93

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

Saved successfully!

Ooh no, something went wrong!