Полиморфна ли эта функция? Не совсем понимаю сущность полиморфизма, помогите пожалуйста разобраться. Правильно ли я понимаю, что метод Logger.makeLog() является полиморфным?#!/usr/bin/env python3
class Product:
def __init__(self, title, logger):
self.title = title
self.logger = logger
def setPrice(self, price):
try:
if price

21 Авг 2019 в 06:58
192 +1
0
Ответы
1

Yes, you are correct. The method Logger.makeLog() in the given code example exhibits polymorphism. Polymorphism in object-oriented programming allows objects of different classes to be treated as objects of a common superclass (or interface) and execute methods specific to their own class.

In this case, the makeLog() method in the Logger class dynamically calls either the printLog() or fillLog() method based on the type of logging specified during the initialization of the Logger object. This flexibility in method invocation based on the type of object or parameters passed can be considered an example of polymorphism.

20 Апр 2024 в 13:10
Не можешь разобраться в этой теме?
Обратись за помощью к экспертам
Гарантированные бесплатные доработки в течение 1 года
Быстрое выполнение от 2 часов
Проверка работы на плагиат
Поможем написать учебную работу
Прямой эфир