21-inheritance - 1 CSE 143 Lecture 21 Inheritance, static...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 CSE 143 Lecture 21 Inheritance, static slides created by Alyssa Harding http://www.cs.washington.edu/143/ 2 Inheritance Weve seen how the mechanics of inheritance work We seen some things about extending classes, super calls, and inherited methods Now were going to see how we can program with inheritance to make our lives easier 2 3 Example: StutterList We want a class that has all the functionality of ArrayList but adds everything twice For instance, the following code StutterList<String> s = new StutterList<String>(); s.add(hello); System.out.println(s); outputs [hello,hello] 4 Example: StutterList How would we do this? We could write an entirely new class by copying and pasting the ArrayList<E> code But thats redundant We could change the ArrayList<E> code to include our new functionality But this is invasive change It would ruin any code that depended on the original functionality 2 3 Example: StutterList We want a class that has all the functionality of ArrayList but adds everything twice For instance, the following code StutterList<String> s = new StutterList<String>(); s.add(hello); System.out.println(s); outputs [hello,hello] 4 Example: StutterList How would we do this? We could write an entirely new class by copying and pasting the ArrayList<E> code But thats redundant We could change the ArrayList<E> code to include our new functionality But this is invasive change It would ruin any code that depended on the original functionality 3 5 Example: StutterList We want additive , not...
View Full Document

Page1 / 10

21-inheritance - 1 CSE 143 Lecture 21 Inheritance, static...

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

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