[go: up one dir, main page]

0% found this document useful (0 votes)
51 views13 pages

2.4 Object-Oriented Paradigm Inheritance

1) The document introduces the concept of inheritance in object-oriented programming, where a child class inherits attributes and methods from a parent class. 2) As an example, it discusses how a game about different zoo animals could use inheritance, with an "Animal" parent class that bird, snake, and other animal child classes inherit from. 3) A diagram shows the inheritance relationships between classes like "Penguin" and "Snake" for the zoo game, to organize shared and unique attributes and behaviors across animal types in a structured way.

Uploaded by

Giovanni Ramirez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views13 pages

2.4 Object-Oriented Paradigm Inheritance

1) The document introduces the concept of inheritance in object-oriented programming, where a child class inherits attributes and methods from a parent class. 2) As an example, it discusses how a game about different zoo animals could use inheritance, with an "Animal" parent class that bird, snake, and other animal child classes inherit from. 3) A diagram shows the inheritance relationships between classes like "Penguin" and "Snake" for the zoo game, to organize shared and unique attributes and behaviors across animal types in a structured way.

Uploaded by

Giovanni Ramirez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

WELCOME TO ENGLISH CLASS

WELCOME TO ENGLISH CLASS

“ What would you do if you were not afraid?”


 
Sheryl Sandberg
Object-Oriented Paradigm: inheritance
DATE

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.

OOP design: inheritance


Inheritance makes it possible to create a new child class that inherits the attributes and methods of the original
(parent) class. The term 'parent class' is also referred to as superclass or base class, while 'child classes' can also be
referred to as subclasses or derived classes.
Inheritance can be used when you observe a 'kind-of' or 'is-a' relationship between classes. You can say, for example,
that "a dog is an animal" or "a dog is a kind of animal".
Text Object-Oriented Paradigm : Inheritance

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

Figure 1: Inheritance diagram for the zoo game


This high-level diagram shows us the names of the classes and the relationship between them. You can see that a
penguin is a non-flying bird and that a snake is a reptile. It is important to note that this is not a biological taxonomy; the
classes and relationships are those relevant for the zoo game.
SELF-EVALUATION

Answer the following questions:


 
1. Entiendo qué es Inheritance.
Si No Tal vez

2. Entiendo cómo se aplica el concepto de Inheritance a


situaciones de la vida real.
Si No Tal vez

Entiendo cómo se usa la estrategia text-to-world.


Si No Tal vez

You might also like