ch1 - CHAPTER 1 OBJECT-ORIENTED CONCEPTS CHAPTER OBJECTIVES...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
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 increase the independence of class A : its effectiveness will not be affected by any changes to class B that do not affect the method specifications of class B . When users focus on what a class provides to users rather than on the implementation details of that class, they are applying the Principle of Data Abstraction : A user’s code should not access the implementation details of the class 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
used. One important application of the Principle of Data Abstraction is that if class A uses class B , then class A 's methods should not access class B 's fields. In fact, class B 's fields should be accessed only in class B 's method definitions. This turns out to be a benefit to users of class B because they will be unaffected if the developer of class B decides to replace the old fields with new ones. For example, suppose the following definition is made outside of the String class: String name; Currently, one of the fields in the String class is an int field named count . But an expression such as name.count would be a violation of the Principle of Data Abstraction because whether or not the String class has a count field is an implementation detail. The developer of the String class is free to make any changes to the String class that do not affect the method specifications. Most programming languages, including Java, have features that enable a
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 41

ch1 - CHAPTER 1 OBJECT-ORIENTED CONCEPTS CHAPTER OBJECTIVES...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online