Vererbung mit verstecken Methoden und Attributen bei ABCs
- Herausforderungen bei Vererben von
_<protected>
und __<private>
Methoden und Attributen
from abc import ABC, abstractmethod
class Driveable(ABC):
@abstractmethod
def __drive(self):
pass
class Robot(Driveable):
def __init__(self, name):
self.name = False
self.__is_flying = False
self.__is_driving = False
def __drive(self):
if not self.is_flying:
self.__is_driving = True
self.__is_flying = False
print(f"{self.name} fährt.")
robi_1 = Robot("Robi")
"""
>>> TypeError: Can't instantiate abstract class Robot
without an implementation for abstract method '_Driveable__drive'
"""