Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RefactorTask_Lyft #151

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added ._.git
Binary file not shown.
Binary file added ._.gitignore
Binary file not shown.
Binary file added ._README.md
Binary file not shown.
Binary file added ._car.py
Binary file not shown.
Binary file added ._testCar.py
Binary file not shown.
35 changes: 35 additions & 0 deletions battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from abc import ABC, abstractmethod
from service import Serviceable
from datetime import date

class Battery(Serviceable):

@abstractmethod
def needs_service(self) -> bool:
pass

class SpindleBattery(Battery):
def __init__(self, current_date:date, last_service_date:date):
self.current_date = current_date
self.last_service_date = last_service_date

def needs_service(self):
service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 3)

if service_threshold_date < self.current_date:
return True
else:
return False

class NubbinBattery(Battery):
def __init__(self, current_date:date, last_service_date:date):
self.current_date = current_date
self.last_service_date = last_service_date

def needs_service(self):
service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 4)

if service_threshold_date < self.current_date:
return True
else:
return False
34 changes: 27 additions & 7 deletions car.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
from abc import ABC, abstractmethod
from service import Serviceable
from battery import Battery
from engine import Engine

class Car(Serviceable):
def __init__(self, Engine, Battery, Tire):
self.engine = Engine
self.battery = Battery
self.tire = Tire

def needs_service(self) -> bool:
Flag = False
print("======")
if self.engine.needs_service():
print("Engine needs Service!")
Flag = True
if self.battery.needs_service():
print("Battery needs Service!")
Flag = True

if self.tire.needs_service():
print("Tires need Service!")
Flag = True

if Flag == False:
print("Service is not required!")
print("======")
return Flag

class Car(ABC):
def __init__(self, last_service_date):
self.last_service_date = last_service_date

@abstractmethod
def needs_service(self):
pass
38 changes: 38 additions & 0 deletions carFactory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from car import Car
from engine import *
from battery import *
from tire import *
from datetime import date

class CarFactory():

@staticmethod
def create_calliope(current_date:date, last_service_date:date, current_mileage:int, last_service_mileage:int, tire:Tire):
engine = CapuletEngine(current_mileage, last_service_mileage)
battery = SpindleBattery(current_date, last_service_date)
return Car(engine, battery, tire)

@staticmethod
def create_glissade(current_date:date, last_service_date:date, current_mileage:int, last_service_mileage:int, tire:Tire):
engine = WilloughbyEngine(current_mileage, last_service_mileage)
battery = SpindleBattery(current_date, last_service_date)
return Car(engine, battery, tire)

@staticmethod
def create_palindrome(current_date:date, last_service_date:date, warning_light_is_on:bool, tire:Tire):
engine = SternmanEngine(warning_light_is_on)
battery = SpindleBattery(current_date, last_service_date)
return Car(engine, battery, tire)

@staticmethod
def create_rorschach(current_date:date, last_service_date:date, current_mileage:int, last_service_mileage:int, tire:Tire):
engine = WilloughbyEngine(current_mileage, last_service_mileage)
battery = NubbinBattery(current_date, last_service_date)
return Car(engine, battery, tire)

@staticmethod
def create_thovex(current_date:date, last_service_date:date, current_mileage:int, last_service_mileage:int, tire: Tire):
engine = CapuletEngine(current_mileage, last_service_mileage)
battery = NubbinBattery(current_date, last_service_date)
return Car(engine, battery, tire)

36 changes: 36 additions & 0 deletions engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from abc import ABC, abstractmethod
from service import Serviceable

class Engine(Serviceable):

@abstractmethod
def needs_service(self) -> bool:
pass

class CapuletEngine(Engine):
def __init__(self, current_mileage:int, last_service_mileage:int):
self.current_mileage = current_mileage
self.last_service_mileage = last_service_mileage

def needs_service(self):
return self.current_mileage - self.last_service_mileage > 30000

class WilloughbyEngine(Engine):
def __init__(self, current_mileage:int, last_service_mileage:int):
self.current_mileage = current_mileage
self.last_service_mileage = last_service_mileage

def needs_service(self):
return self.current_mileage - self.last_service_mileage > 60000


class SternmanEngine(Engine):
def __init__(self, warning_light_is_on:bool):

self.warning_light_is_on = warning_light_is_on

def needs_service(self):
if self.warning_light_is_on:
return True
else:
return False
Empty file removed engine/__init__.py
Empty file.
13 changes: 0 additions & 13 deletions engine/capulet_engine.py

This file was deleted.

Empty file removed engine/model/__init__.py
Empty file.
12 changes: 0 additions & 12 deletions engine/model/calliope.py

This file was deleted.

12 changes: 0 additions & 12 deletions engine/model/glissade.py

This file was deleted.

12 changes: 0 additions & 12 deletions engine/model/palindrome.py

This file was deleted.

12 changes: 0 additions & 12 deletions engine/model/rorschach.py

This file was deleted.

12 changes: 0 additions & 12 deletions engine/model/thovex.py

This file was deleted.

15 changes: 0 additions & 15 deletions engine/sternman_engine.py

This file was deleted.

13 changes: 0 additions & 13 deletions engine/willoughby_engine.py

This file was deleted.

8 changes: 8 additions & 0 deletions service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

from abc import ABC, abstractmethod

class Serviceable(ABC):

@abstractmethod
def needs_service(self) -> bool:
pass
Empty file removed test/__init__.py
Empty file.
Loading