Algorithms and OOD (CSC 207 2014S) : EBoards

CSC207.01 2014S, Class 15: Inheritance


Overview

Preliminaries

Admin

Upcoming Work

About Exam 1

Questions on the Homework

Questions on inheritance and polymorphism

Why use interfaces when I can just use inheritance?

What if you want to support two different interfaces?

Images are renderable

Images are multipliable

And multiple inheritance is really confusing. What if both superclasses have a method with the same signature? (implementing multiple inheritance is also a PITN)

Arrays are probably Iterable, Clonable, and Comparable

There's not much data or methodology you'd want to inherit

If my class extends a class that implements multiple interfaces, does my class also implement those interfaaces?

Yes, and you don't even need to say so explicitly. (I hope.)

How do I use inheritance in place of interfaces?

We've seen that if A implements B then we can use A in place of B.

It's also the case that if A extends B then we can use A in place of B.

What are the big differences between inheritance and implementation?

In inheritance, you get copies of the fields and methods.

In inheritance, you need to be careful in the design of your constructors (see lab for details)

Lab

Thinking about ways to group blocks

TextBlock block1 = new TextBlock("Hello");
BoxedBlock block2 = new BoxedBlock(block1);

vs.

TextBlock block1 = new TextBlock("Hello");
TextBlock block2 = new BoxedBlock(block1);

vs.

TextBlock block2 = new BoxedBlock(new TextBlock("Hello"));

Problem 7

Copyright (c) 2013-14 Samuel A. Rebelsky.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.