From f684cacb2f6a5d135a08245f76fd248e84538653 Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Wed, 6 Jul 2022 13:54:21 -0500 Subject: [PATCH] saving progress on implementing abstracted methods --- fleet.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/fleet.py b/fleet.py index c785033..6d70996 100644 --- a/fleet.py +++ b/fleet.py @@ -36,23 +36,24 @@ class Vehicle(ABC): # https://www.geeksforgeeks.org/inheritance-and-composition-in-python/ @abstractmethod - def __init__(self, gpsPosition, velocity, weight, velocityType, weightType): + def __init__(self, _gpsPosition, _velocity, _weight, _velocityType, _weightType, _status): self.vehicleObject = Fleet() - self.gpsPosition = [0,0] - self.velocity = 0 - self.velocityType = "kph" - self.weightType = "kg" - self.weight = 0 + self.gpsPosition = _gpsPosition + self.velocity = _velocity + self.velocityType = _weight + self.weightType = _velocityType + self.weight = _weightType + self.status = _status class GroundVehicleInterface(ABC): '''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 + print("Traveling") class GroundVehicle(Vehicle, GroundVehicleInterface): - @abstractmethod def __init__(self, volume): # default value set to true. Many ground vehicles will have trailers or train cars. Modified as needed @@ -82,17 +83,22 @@ Train1 = Train(20, 2) Train1.displayCarCount() 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 +# 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): +class semi_Truck(RoadVehicle): def __init__(self, _noOfTrailersAttached): self.noOfTrailersAttached = _noOfTrailersAttached + super().travel(Vehicle.status) + # Don't modify passed in values unless absolutely necessary def displayNoOfTrailersAttached(self): print(self.noOfTrailersAttached) def travel(self): - print("Currently unloading") + print(Vehicle.status) Semi_Truck1 = semi_Truck(f"This truck has {2} trailers attached.") # Remember to be careful to check that you are running the method on an instance of the class, not on the class definition. -Semi_Truck1.displayNoOfTrailersAttached() \ No newline at end of file +Semi_Truck1.displayNoOfTrailersAttached() + + +# Next - implement abstracted methods and constructor classes. Demonstrate use of super if Python supports it. \ No newline at end of file