Dale - Computer Science Illuminated 203

Dale - Computer Science Illuminated 203 - 6.4 Important...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
176 Chapter 6 Problem Solving and Algorithm Design Name class This class has the same two responsibilities: initialize and print ; however, the algorithms are different. For Initialize , the user must be prompted to enter the name and the algorithm must read the name. For Print , the first and last names must be output with appropriate labels. Address, Telephone, and E-mail classes The algorithms for the responsi- bilities for these classes are mirror images of the algorithms for class Name. We stop the design at this point. Go back to the beginning of Chapter 6 and look at the top-down design for the same problem. The designs are quite different. Is one better than the other? Well, the object-oriented design has created several classes that might be useful in other contexts. Reusability is one of the great advantages of an object-oriented design. Classes designed for one problem can be used in another, because each class is self-contained; that is, each class is responsible for its own behavior.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 6.4 Important Threads In this chapter, we have mentioned several topics in passing that are important not only in problem-solving but in computing in general. Let’s review some of the common threads discussed in this chapter. Information Hiding Several times we have used the idea of deferring the details. We have used it in the context of giving a name to a task and not worrying about how the task is to be implemented until later. The details of the implementation are deferred to a later time. Deferring the details in a design has distinct advantages. The details of a design are hidden from the higher levels. The designer sees just the details that are relevant at a particular level of the Print Print line “First name: ” + firstName Print line “Last name: ” + lastName Initialize “Enter the first name.” Read a string into firstName “Enter the last name.” Read a string into lastName...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online