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

code refectored #129

Open
wants to merge 1 commit 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
12 changes: 7 additions & 5 deletions car.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from abc import ABC, abstractmethod
from abc import abstractmethod
from service import Servicable


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

@abstractmethod
def needs_service(self):
pass
self.engine.need_services() or self.battery.needs_service()
43 changes: 43 additions & 0 deletions car_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from re_battery.battery import NubbinBattery
from re_battery.spindlerbattery import SpindlerBattery
from car import Car
from re_engin.capulet_engine import CapuletEngine
from re_engin.sternman_engine import SternmanEngine
from re_engin.willoughby_engine import WiloughByEngine


class CarFactory:
@staticmethod
def create_calliope(current_date, last_service_date, current_mileage, last_service_mileage):
engine = CapuletEngine(current_mileage, last_service_mileage)
battery = SpindlerBattery(current_date, last_service_date)
car = Car(engine, battery)
return car

@staticmethod
def create_glissade(current_date, last_service_date, current_mileage, last_service_mileage):
engine = WiloughByEngine(current_mileage, last_service_mileage)
battery = SpindlerBattery(current_date, last_service_date)
car = Car(engine, battery)
return car

@staticmethod
def create_palindrome(current_date, last_service_date, warning_light_is_on):
engine = SternmanEngine(warning_light_is_on)
battery = SpindlerBattery(current_date, last_service_date)
car = Car(engine, battery)
return car

@staticmethod
def create_rorschach(current_date, last_service_date, current_mileage, last_service_mileage):
engine = WiloughByEngine(current_mileage, last_service_mileage)
battery = NubbinBattery(current_date, last_service_date)
car = Car(engine, battery)
return car

@staticmethod
def create_thovex(current_date, last_service_date, current_mileage, last_service_mileage):
engine = CapuletEngine(current_mileage, last_service_mileage)
battery = NubbinBattery(current_date, last_service_date)
car = Car(engine, battery)
return car
Binary file added class diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions re_battery/battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from abc import ABC


class Battery(ABC):
def needs_service(self):
pass
16 changes: 16 additions & 0 deletions re_battery/nubbinBattery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from year_to_date import add_years_to_date
from battery import Battery


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

def needs_services(self):
date_which_battery_serviced_by = add_years_to_date(
self.last_service_date + 2)
if date_which_battery_serviced_by < self.current_date:
return True
else:
return False
16 changes: 16 additions & 0 deletions re_battery/spindlerbattery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from year_to_date import add_years_to_date
from battery import Battery


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

def need_services(self):
date_which_battery_serviced_by = add_years_to_date(
self.last_service_date + 2)
if date_which_battery_serviced_by < self.current_date:
return True
else:
return False
10 changes: 10 additions & 0 deletions re_engin/capulet_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from engine import Engine


class CapuletEngine(Engine):
def __init__(self, current_milage, last_service_milage):
self.last_service_milage = last_service_milage
self.current_milage = current_milage

def need_services(self):
return self.current_milage - self.last_service_milage > 30000
6 changes: 6 additions & 0 deletions re_engin/engin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from abc import ABC


class Engine(ABC):
def need_services(self):
pass
10 changes: 10 additions & 0 deletions re_engin/sternman_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from engine import Engine


class SternmanEngine(Engine):
def __init__(self, current_milage, last_service_milage):
self.current_milage = current_milage
self.last_service_milage = last_service_milage

def need_services(self):
return self.current_milage - self.last_service_milage > 30000
10 changes: 10 additions & 0 deletions re_engin/willoughby_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from engine import Engine


class WiloughByEngine(Engine):
def __init__(self, current_milage, last_service_milage):
self.current_milage = current_milage
self.last_service_milage = last_service_milage

def need_services(self):
return self.current_milage - self.last_service_milage > 30000
3 changes: 3 additions & 0 deletions service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Service():
def need_services(self):
pass
3 changes: 3 additions & 0 deletions year_to_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def add_years_to_date(original_date, years_to_add):
result = original_date.replace(year=original_date.year + years_to_add)
return result