Skip to content

Instantly share code, notes, and snippets.

View jonascheng's full-sized avatar
🏠
Working from home

Jonas Cheng jonascheng

🏠
Working from home
View GitHub Profile
@jonascheng
jonascheng / AbstractSerializedEmployeeClass.py
Created June 9, 2019 15:46
SOLID-AbstractSerializedEmployeeClass
import abc
import datetime
class DBStore(abc.ABC):
@abc.abstractmethod
def connect(self):
return NotImplemented
@abc.abstractmethod
@jonascheng
jonascheng / SerializedEmployeeClass.py
Last active June 9, 2019 15:47
SOLID-SerializedEmployeeClass
import datetime
class MySQLStore:
def connect(self):
print('connect to mysql database')
def serialize(self, first_name: str , last_name: str, birth: datetime, hourly_rate: int, labor_hours: int):
print('serialized data to mysql database')
@jonascheng
jonascheng / InheritedBirdClass.py
Created June 9, 2019 05:03
SOLID-InheritedBirdClass-ISP
class Dove(FlyableBird):
def walk(self):
return 0.1
def fly(self):
return 10
class Eagle(FlyableBird):
@jonascheng
jonascheng / BirdClass.py
Created June 9, 2019 05:01
SOLID-BirdClass-ISP
import abc
class Walkable(abc.ABC):
@abc.abstractmethod
def walk(self):
return NotImplemented
class Flyable(abc.ABC):
@jonascheng
jonascheng / PenguinClass
Last active June 9, 2019 04:55
SOLID-PenguinClass
class Penguin(Bird):
def walk(self):
return 1
def fly(self):
raise Exception('I cant fly')
@jonascheng
jonascheng / InheritedBirdClass.py
Last active June 9, 2019 04:55
SOLID-DoveEagleClass
class Dove(Bird):
def walk(self):
return 0.1
def fly(self):
return 10
class Eagle(Bird):
@jonascheng
jonascheng / BirdClass.py
Last active June 9, 2019 04:54
SOLID-BirdClass
import abc
class Bird(abc.ABC):
@abc.abstractmethod
def walk(self):
return NotImplemented
@abc.abstractmethod
def fly(self):
@jonascheng
jonascheng / SalesPersonClass.py
Created June 9, 2019 02:47
SOLID-SalesPersonClass
class SalesPerson(Employee):
@property
def bonus(self):
return self._bonus
@bonus.setter
def bonus(self, bonus):
self._bonus = bonus
@jonascheng
jonascheng / EmployeePrintClass.py
Last active June 8, 2019 15:08
SOLID-EmployPrintClass
class EmployeePrinterForHR:
def printCSV(employee: Employee):
print(u'{},{},{}'.format(employee.first_name, employee.last_name, employee.wage))
class EmployeePrinterForIT:
def printCSV(employee: Employee):
print(u'{},{},{}'.format(employee.first_name, employee.last_name, employee.birth))
@jonascheng
jonascheng / EmployeeClassWithPrintMethods.py
Created June 8, 2019 14:53
SOLID-EmployeeClassWithPrintMethods
import datetime
class Employee:
// ...
def printForHR(self):
print(u'{},{},{}'.format(self.first_name, self.last_name, self.wage))
def printForIT(self):
print(u'{},{},{}'.format(self.first_name, self.last_name, self.birth))