-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcustomer.py
More file actions
72 lines (58 loc) · 1.51 KB
/
customer.py
File metadata and controls
72 lines (58 loc) · 1.51 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
__author__ = 'Bruno'
class Customer:
"""
Customer class
"""
def __init__(self, name="", age=0):
"""
Constructor
:param name: costumer's name
:param age: costumer's age
"""
self.name = name
self.age = age
class CustomerDao:
"""
Customer's DataAccess class
"""
@classmethod
def save(cls, customer):
"""
Saves the Customer in a database
:param customer: costumer to save
"""
print("Saving customer {} with {} years".format(customer.name, customer.age))
class CustomerValidate:
"""
This class validate if a client is
valid
"""
@classmethod
def validate(cls, customer):
"""
Validate customer
:param customer: customer to be validated
:return: True or False
"""
if customer.name == "":
print("Customer {} is not ok".format(customer.name))
return False
else:
print("Customer {} is ok".format(customer.name))
return True
class CustomerFacade:
"""
Facade class to call
all rules to save a customer
"""
def __init__(self):
self.dao = CustomerDao()
self.validate = CustomerValidate()
def save(self, customer):
"""
Save the customer
:param customer:
"""
if not self.validate.validate(customer):
raise Exception("Customer {} is invalid".format(customer.name))
self.dao.save(customer)