CS305j Introduction to Computing Inheritance and Polymorphism
1
Topic 26
Introduction to Inheritance and Polymorphism
"One purpose of CRC cards [a design tool] is to fail early, to fail often, and to fail
- inexpensively. It is a lot cheaper to tear up a
bunch of cards that it would be to reorganize a large amount of source code. "
- Cay Horstmann
Based on slides for Building Java Programs by Reges/Stepp, found at http://faculty.washington.edu/stepp/book/
CS305j Introduction to Computing Inheritance and Polymorphism
2
Managing Complexity
software development: The practice of conceptualizing, designing, constructing, documenting, and testing large- scale computer programs. (a.k.a. software engineering) Challenges:
– managing lots of programmers – dividing work – avoiding redundant code (wasted effort) – finding and fixing bugs – testing – maintenance (between 50% and 90% of cost)
Code reuse: writing code once and reusing it in different applications and programs.
CS305j Introduction to Computing Inheritance and Polymorphism
3
Categories
Often we categorize objects in the real world starting with a general category and then becoming more specific.
– Let's think about people, human beings. What things does every human being have? What does every human being know how to do? – We could draw a diagram of these things. Something like this:
data behaviors Person
name age favorite movie talk play
CS305j Introduction to Computing Inheritance and Polymorphism
4
Subcategories
Within the broad range of people, let's talk about a specific group: members of the University
– What new attributes and behaviors are there? – Let's assume that all members are people, and draw them as a subcategory of persons, as shown to the right – Members of the University add some new abilities and attributes.
- UTEID
- work
– Employees perform some of the
- riginal person's abilities differently.
- talk about the University
– Notice we don't repeat things from Person
Person
name age favorite movie talk play Member of the University UTEID what I owe books checked
- ut
talk (about UT) work check out book