From 5ea0c7986026780453a350d24e0cbfae89a7f363 Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Fri, 1 Jul 2022 11:54:29 -0500 Subject: [PATCH] saving further inheiritance work --- fleet.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/fleet.py b/fleet.py index 4c03c96..5c6bb94 100644 --- a/fleet.py +++ b/fleet.py @@ -1,4 +1,5 @@ from abc import ABC, abstractmethod +# ABC is imported from the standard library since Python does not natively support abstract methods and classes. class Fleet(): vehicles = ["7E19H2", "N9460G32581A3", "BN4681"] @@ -44,7 +45,7 @@ class Vehicle(ABC): self.weight = 0 class GroundVehicleInterface(ABC): - '''Resource on Python interfaces. This is duck typed. https://realpython.com/python-interface/''' + '''Resource on Python interfaces. This is duck typed. https://realpython.com/python-interface/ Interfaces make a contract that a method must be implemented if an interface is inherited and allows differing implementations of the same method.''' @abstractmethod def travel(self): Vehicle.velocity = self.moveGroundVehicle @@ -79,4 +80,16 @@ class Train(GroundVehicle): Train1 = Train(20, 2) Train1.displayCarCount() -Train1.displayLocomotiveCount() \ No newline at end of file +Train1.displayLocomotiveCount() + +# At this point, my code should print out the values from the car count and the locomotive count. Further demonstration of abstract and concrete classes to follow + +class semi_Truck(GroundVehicle): + def __init__(self, _noOfTrailersAttached): + self.noOfTrailersAttached = _noOfTrailersAttached + def displayNoOfTrailersAttached(self): + print(self.noOfTrailersAttached) + +Semi_Truck1 = semi_Truck(f"This truck has {2} trailers attached.") + +semi_Truck.displayNoOfTrailersAttached() \ No newline at end of file