-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataClasses.py
More file actions
108 lines (87 loc) · 3.33 KB
/
DataClasses.py
File metadata and controls
108 lines (87 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# ---------------------------------------------------------- #
# Title: DataClasses.py - Assignment09
# Description: A module of data classes for Assignment09
# ChangeLog (Who,When,What):
# RRoot,1.1.2020, Created starting script
# ASimpson, 03/21/2020, Modified this script for Assignment09
# ---------------------------------------------------------- #
if __name__ == "__main__":
raise Exception("This file is not meant to ran by itself")
class Person(object):
"""Stores data about a person:
properties:
first_name: (string) with the persons's first name
last_name: (string) with the persons's last name
methods:
to_string() returns comma separated product data (alias for __str__())
changelog: (When,Who,What)
RRoot,1.1.2030,Created Class
"""
# -- Constructor --
def __init__(self, first_name, last_name):
# -- Attributes --
self.__first_name = first_name
self.__last_name = last_name
# -- Properties --
@property
def first_name(self):
return str(self.__first_name).title()
@first_name.setter
def first_name(self, value):
if not str(value).isnumeric():
self.__first_name = value
else:
raise Exception("Names cannot be numbers")
@property
def last_name(self):
return str(self.__last_name).title()
@last_name.setter
def last_name(self, value):
if not str(value).isnumeric():
self.__last_name = value
else:
raise Exception("Names cannot be numbers")
# -- Methods --
def to_string(self):
""" Explicitly returns a string with this object's data """
return self.__str__()
def __str__(self):
""" Implicitly returns a string with this object's data """
return self.first_name + ',' + self.last_name
class Employee(Person): # Inherits from Person
"""Stores data about an Employee:
properties:
employee_id: (int) with the employees's ID
first_name: (string) with the employees's first name
last_name: (string) with the employees's last name
methods:
to_string() returns comma separated product data (alias for __str__())
changelog: (When,Who,What)
RRoot,1.1.2030,Created Class
"""
def __init__(self, employee_id, first_name, last_name):
# Attributes
self.__employee_id = employee_id
self.first_name = first_name
self.last_name = last_name
# --Properties--
@property
def employee_id(self):
return self.__employee_id
@employee_id.setter
def employee_id(self, value):
if str(value).isnumeric():
self.__last_name = value
else:
raise Exception("IDs must be numbers")
# --Methods--
def to_string(self): # Overrides the original method (polymorphic)
""" Explicitly returns a string with this object's data """
# Linking to self.__str__() does not work with inheritance
data = super().__str__() # get data from parent(super) class
return str(self.employee_id) + ',' + data
def __str__(self): # Overrides the original method (polymorphic)
""" Implicitly returns field data """
data = super().__str__() # get data from parent(super) class
return str(self.employee_id) + ',' + data
# --End of Class --