2.4 Object-Oriented Paradigm Inheritance
2.4 Object-Oriented Paradigm Inheritance
DATE
Objective:
Students will apply the concept of "Inheritance" to a real-life situation.
AGENDA
WARM UP:
Review personal information questions and answer.
CLASS ACTIVITY:
• New Vocabulary
• Reading Strategy: Text-connections (text-self)
• Reading: OOP design: inheritance
Wrap- Up
Read a UML diagram, then create one similar to the text but
using a different class.
VOCABULARY
Inheritance
inherits
feed
lay eggs
spin webs
behaviour
hop
slither
open-headed arrows
WARM-UP
Animals games
Video: Reading Strategy
https://www.youtube.com/watch?v=R21XJMNplLU
Text Object-Oriented Paradigm : Inheritance
You will do this activity in groups. First, you will read the text below. After that, you will create a UML diagram, similar
to the one in the text, but using a different class. For example, it can be “Transport”, when you finish, you can share
and compare your diagrams.
Inheritance diagrams
A classic example of inheritance involves an animal superclass.
Imagine that you are going to develop a game for children that allows them to play the role of a zookeeper. The zoo will have
many different animals, and you could make a long list of every different animal type and develop a class definition for each.
However, you would soon notice that every class has a set of attributes and methods in common. For example, all of the
animals would have a name and would be able to feed and move.
You could use a single animal class and add an animal-type attribute that would specify the type of animal. But different
types of animals will need different methods (for example, birds need to be able to lay eggs and spiders to spin webs). Even
where the animals have a method in common, such as move, the implementation would need lots of 'if' statements to
ensure the correct movement behaviour (for example, kangaroos hop, whereas snakes slither). Inheritance can solve this
problem.
Text Object-Oriented Paradigm : Inheritance
Inheritance is an OOP technique where child classes are derived from a parent class and inherit all of the attributes and
methods from the parent. These properties don't need to be redefined for the child (the child shares the code from the
parent class). However, you can add extra attributes and methods and change the behaviour of any inherited methods as
required.
In a UML diagram, inheritance is represented with open-headed arrows. The arrows point up from the child class to the
parent class. The figure below shows a high-level inheritance diagram for the zoo game.
Text Object-Oriented Paradigm : Inheritance