Lesson-27 | Composition and Inheritance | [OOP in Python]

preview_player
Показать описание
This is the lesson number 27 of the lesson series on Object Oriented Programming (OOP) in Python. It will be a complete course with the aim is to cover almost everything needed in Object Oriented Programming.

In this lesson we will first discus that how to decide whether we should use Class Inheritance or just have multiple classes without Inheritance. The discussion will also lead to Composition.

Link to complete playlist:

Lesson Code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*Review Questions of the Lesson*
1- For two classes, Vehicle and Car, should we use Inheritance?
2- Give one example of class Composition.

#OOP #ObjectOrientedProgramming #Python
Рекомендации по теме
Комментарии
Автор

2)
Class YouTube:
and
Class Channel:

awais_
Автор

Nice lecture as usual ..keep on uploading more...thank u

Astromoola
Автор

1-Not necessary, there is a 'is a' composition relation between them, we can apply any method on car class in class vehicle by creating reference to the object as in Deck class but the other scenario can also be true for some cases.

muneebirfan
Автор

1. Yes, we can use Inheritance for classes, Vehicles and Car because Car can be used as child class and Vehicle can be its parent class. Also there is "is a" relation between car and a vehicle.

ibtisamumer
Автор

2. Horse class can be composed by an another object of type Tail. Composition allows to express that relationship by saying that a Horse has a Tail.

faryalnasir
Автор

1)yes, as Car "is a" Vehicle so we can use class inheritance for that classes

hafizaqib
Автор

1. Because there is a "is a " relationship between them. So inheritance can be used

syedfarazabbas
Автор

1-Yes, it satisfies 'is a' relation so we can use inheritance.
2-House, rooms .There is "has a" relation.

yusrakashif
Автор

1. Yes, both of them can be inherited because the 'is a' relation is applied to them.

hamzamushtaqtoor
Автор

2. class home and class rooms can be an example of class Composition because home has rooms in it.

aqsaamjad
Автор

1)there is natural inheritence as both are synonyms
2)class city and country

dawood
Автор

1. Yes, because as a car 'is a' vehicle the relation between them so we should use class inheritance.

arbabkhalid
Автор

1)Yes, car is inherited from vehicle so there is "is-a" relationship between these two.
2)A book has chapters "a has" relationship between these two.

zainzakir
Автор

2. class House and class room is an example of class composition because "has a " relation.

knowledgehub
Автор

Yes, because there exit an 'is a' relation between vehicle and car, where vehicle might be a parent class with car as a child class.

maryumkainat
Автор

1-yes we can use inheritance as a class car is a child of class vehicle. there is "is a" relationship in both.

ayeshaaslam
Автор

1. yes inheritance can be used because this involve "is-a" relation .car is inherited from vehicle

knowledgehub
Автор

1-Yes car is also a vehicle, so it can be in herited form vehicle. is a relation

ProphetPearls
Автор

1. Yes, we should use class inheritance because there is a relation between car and vehicle.

aqsaamjad
Автор

1- Yes, we should use inheritance as car is a type of vehicle

moadibnasir
welcome to shbcf.ru