CHAPTER 1

Object-Oriented Concepts

CHAPTER OBJECTIVES

  1. Compare a user's view of a class with a developer's view of that class.
  2. Understand how inheritance promotes code re-use.
  3. Understand how polymorphic references can be useful.
  4. Be able to create class diagrams in the Unified Modeling Language.

1.1 Data Abstraction

A user of a class concentrates on the class's method specifications, that is, what a class provides. A developer of a class, on the other hand, focuses on the class's fields and method definitions, that is, how the class is defined. This separation—called data abstraction —of what from how is an essential feature of object-oriented programming. For example, programmers who use the String class will not care about the fields that represent a string or how the methods are defined. Such details would be of no help when you are trying to develop a class that uses the string class, but were essential to the developers of the String class.

In general, suppose you are a programmer who is developing class A, and during development, you decide that you will need the services of class B. If someone else has already completed the definition of class B, you should simply use that class rather than re-inventing the wheel. But even if you must define the class, B yourself, you can simply create the method specifications for class B and postpone any further work on class B until after you have completed the development of class A. By working with class B's method specifications, you ...

Get Data Structures and the Java Collections Framework, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.