18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>Software</strong> design 23<br />

Inheritance diagram<br />

Responsibilities:<br />

Telephone<br />

Establish contact with another phone po<strong>in</strong>t.<br />

Convert sound to/from electrical signals.<br />

Fax mach<strong>in</strong>e<br />

All the responsibilities of a telephone plus:<br />

Convert images to/from electrical signals.<br />

Figure 2.3 Relationship between a telephone and a fax mach<strong>in</strong>e.<br />

Note:<br />

The superclass (telephone) is the class from which a subclass (fax mach<strong>in</strong>e) is <strong>in</strong>herited.<br />

Inheritance requires you to take all the responsibilities from the superclass; you cannot selectively<br />

choose to take only some. However, even though you <strong>in</strong>herit the responsibilities you do not need to use<br />

them.<br />

The <strong>in</strong>heritance relationship is an important concept <strong>in</strong> object-<strong>oriented</strong> programm<strong>in</strong>g as it enables new objects<br />

to be created by specializ<strong>in</strong>g an exist<strong>in</strong>g object. In creat<strong>in</strong>g the new object, only the addition, responsibilities have<br />

to be constructed. The development time for a new software object is reduced as the task of creat<strong>in</strong>g the <strong>in</strong>herited<br />

responsibilities has already been done. This process leads to a dramatic reduction <strong>in</strong> the time and effort required to<br />

create new software objects.<br />

2.8 Polymorphism<br />

In a collection of different objects if all the objects are capable of receiv<strong>in</strong>g a specific message then this message<br />

may be sent to any object <strong>in</strong> the collection. The method executed when this message is received by an object will<br />

depend on the type of the object that receives the message.<br />

For example, <strong>in</strong> a group of <strong>in</strong>dividuals if you ask a person how to take part <strong>in</strong> their favourite sport, you will<br />

probably get many different answers. In effect the message ‘How to take part <strong>in</strong> your favourite sport’ is<br />

polymorphic <strong>in</strong> that the answer you get depends on the <strong>in</strong>dividual person you select to ask. A tennis player for<br />

example, would give a different answer than a golfer.<br />

2.9 Self-assessment<br />

• Expla<strong>in</strong> why the solution to a small problem may not always scale up to solve a much larger and<br />

complex problem.<br />

• What is a “Responsibility”?<br />

• What are the responsibilities of:<br />

• A video camera.<br />

• An alarm clock.<br />

• A traffic light.<br />

• An actress play<strong>in</strong>g the role of Olgar <strong>in</strong> the Three sisters by Chekov.<br />

• What is the relationship between an object, message and a method?<br />

© M A Smith - May not be reproduced without permission

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

Saved successfully!

Ooh no, something went wrong!