123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- from abc import ABC, abstractmethod
- class Employee(ABC):
- def __init__(self, name):
- pass
- @abstractmethod
- def calculate_salary(self):
- pass
- class HourlyEmployee(Employee):
- def __init__(self, hours_worked, hourly_rate):
- self.hours_worked = hours_worked
- self.hourly_rate = hourly_rate
- def calculate_salary(self, ):
- return self.hours_worked * self.hourly_rate
- class SalariedEmployee(Employee):
- def __init__(self, monthly_salary):
- self.monthly_salary = monthly_salary
- def calculate_salary(self):
- return self.monthly_salary
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- class Datebase(ABC):
- def __init__(self):
- pass
- @abstractmethod
- def connect(self):
- pass
- @abstractmethod
- def disconnect(self):
- pass
- @abstractmethod
- def execute(self):
- pass
-
- class MySQLDatabase(Datebase):
-
- def connect(self):
- print("Connecting to MySQL database...")
- def disconnect(self):
- print("Disconnecting from MySQL database...")
- def execute(self, query):
- print(f"Executing query '{query}' in MySQL database...")
- class PostgreSQLDatabase(Datebase):
-
- def connect(self):
- print("Connecting to PostgreSQL database...")
- def disconnect(self):
- print("Disconnecting from PostgreSQL database...")
- def execute(self, query):
- print(f"Executing query '{query}' in PostgreSQL database...")
- def main():
- mysql_db = MySQLDatabase()
- postgresql_db = PostgreSQLDatabase()
- mysql_db.connect()
- mysql_db.execute(
- "SELECT * FROM customers;")
- mysql_db.disconnect()
- postgresql_db.connect()
- postgresql_db.execute(
- "SELECT * FROM customers;")
- postgresql_db.disconnect()
- '''
- hourly_employee = HourlyEmployee(100, 25)
- assert hourly_employee.hours_worked == 100
- assert hourly_employee.hourly_rate == 25
- assert hourly_employee.calculate_salary() == 2500
- salaried_employee = SalariedEmployee(4000)
- assert salaried_employee.monthly_salary == 4000
- assert salaried_employee.calculate_salary() == 4000
- print('Good')
- '''
- if __name__ == '__main__':
- main()
|