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

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

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

<strong>in</strong>stance, wish to identify some of our objects as sellable, <strong>in</strong> which case they could<br />

implement the Sellable <strong>in</strong>terface shown <strong>in</strong> Code Fragment 2.8.<br />

We can then def<strong>in</strong>e a concrete class, Photograph, shown <strong>in</strong> Code Fragment 2.9,<br />

that implements the Sellable <strong>in</strong>terface, <strong>in</strong>dicat<strong>in</strong>g that we would be will<strong>in</strong>g to<br />

sell any of our Photograph objects: This class def<strong>in</strong>es an object that<br />

implements each of the methods of the Sellable <strong>in</strong>terface, as required. In<br />

addition, it adds a method, isColor, which is specialized for Photograph<br />

objects.<br />

Another k<strong>in</strong>d of object <strong>in</strong> our collection might be someth<strong>in</strong>g we could transport. For<br />

such objects, we def<strong>in</strong>e the <strong>in</strong>terface shown <strong>in</strong> Code Fragment 2.10.<br />

Code Fragment 2.8: Interface Sellable.<br />

Code Fragment 2.9 : Class Photograph<br />

implement<strong>in</strong>g the Sellable <strong>in</strong>terface.<br />

117

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

Saved successfully!

Ooh no, something went wrong!