Skip to content

Commit 8436bb5

Browse files
authored
Merge pull request #7 from mickeybeurskens/main
Minor spacing and naming fixes
2 parents a7c23a9 + 1b09506 commit 8436bb5

11 files changed

+61
-26
lines changed

9 - solid/dependency-inversion-after.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from abc import ABC, abstractmethod
22

3+
34
class Order:
45

56
def __init__(self):
@@ -19,13 +20,14 @@ def total_price(self):
1920
total += self.quantities[i] * self.prices[i]
2021
return total
2122

23+
2224
class Authorizer(ABC):
2325
@abstractmethod
2426
def is_authorized(self) -> bool:
2527
pass
2628

2729

28-
class Authorizer_SMS(Authorizer):
30+
class AuthorizerSMS(Authorizer):
2931

3032
def __init__(self):
3133
self.authorized = False
@@ -37,7 +39,8 @@ def verify_code(self, code):
3739
def is_authorized(self) -> bool:
3840
return self.authorized
3941

40-
class Authorizer_Google(Authorizer):
42+
43+
class AuthorizerGoogle(Authorizer):
4144

4245
def __init__(self):
4346
self.authorized = False
@@ -49,7 +52,8 @@ def verify_code(self, code):
4952
def is_authorized(self) -> bool:
5053
return self.authorized
5154

52-
class Authorizer_Robot(Authorizer):
55+
56+
class AuthorizerRobot(Authorizer):
5357

5458
def __init__(self):
5559
self.authorized = False
@@ -73,14 +77,15 @@ class DebitPaymentProcessor(PaymentProcessor):
7377
def __init__(self, security_code, authorizer: Authorizer):
7478
self.security_code = security_code
7579
self.authorizer = authorizer
76-
80+
7781
def pay(self, order):
7882
if not self.authorizer.is_authorized():
7983
raise Exception("Not authorized")
8084
print("Processing debit payment type")
8185
print(f"Verifying security code: {self.security_code}")
8286
order.status = "paid"
8387

88+
8489
class CreditPaymentProcessor(PaymentProcessor):
8590

8691
def __init__(self, security_code):
@@ -91,6 +96,7 @@ def pay(self, order):
9196
print(f"Verifying security code: {self.security_code}")
9297
order.status = "paid"
9398

99+
94100
class PaypalPaymentProcessor(PaymentProcessor):
95101

96102
def __init__(self, email_address, authorizer: Authorizer):
@@ -111,8 +117,8 @@ def pay(self, order):
111117
order.add_item("USB cable", 2, 5)
112118

113119
print(order.total_price())
114-
authorizer = Authorizer_Robot()
120+
authorizer = AuthorizerRobot()
115121
# authorizer.verify_code(465839)
116122
authorizer.not_a_robot()
117123
processor = PaypalPaymentProcessor("[email protected]", authorizer)
118-
processor.pay(order)
124+
processor.pay(order)

9 - solid/dependency-inversion-before.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from abc import ABC, abstractmethod
22

3+
34
class Order:
45

56
def __init__(self):
@@ -19,6 +20,7 @@ def total_price(self):
1920
total += self.quantities[i] * self.prices[i]
2021
return total
2122

23+
2224
class SMSAuthorizer:
2325

2426
def __init__(self):
@@ -44,14 +46,15 @@ class DebitPaymentProcessor(PaymentProcessor):
4446
def __init__(self, security_code, authorizer: SMSAuthorizer):
4547
self.security_code = security_code
4648
self.authorizer = authorizer
47-
49+
4850
def pay(self, order):
4951
if not self.authorizer.is_authorized():
5052
raise Exception("Not authorized")
5153
print("Processing debit payment type")
5254
print(f"Verifying security code: {self.security_code}")
5355
order.status = "paid"
5456

57+
5558
class CreditPaymentProcessor(PaymentProcessor):
5659

5760
def __init__(self, security_code):
@@ -62,6 +65,7 @@ def pay(self, order):
6265
print(f"Verifying security code: {self.security_code}")
6366
order.status = "paid"
6467

68+
6569
class PaypalPaymentProcessor(PaymentProcessor):
6670

6771
def __init__(self, email_address, authorizer: SMSAuthorizer):
@@ -85,4 +89,4 @@ def pay(self, order):
8589
authorizer = SMSAuthorizer()
8690
# authorizer.verify_code(465839)
8791
processor = PaypalPaymentProcessor("[email protected]", authorizer)
88-
processor.pay(order)
92+
processor.pay(order)

9 - solid/interface-segregation-after-comp.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from abc import ABC, abstractmethod
22

3+
34
class Order:
45

56
def __init__(self):
@@ -19,6 +20,7 @@ def total_price(self):
1920
total += self.quantities[i] * self.prices[i]
2021
return total
2122

23+
2224
class SMSAuthorizer:
2325

2426
def __init__(self):
@@ -44,14 +46,15 @@ class DebitPaymentProcessor(PaymentProcessor):
4446
def __init__(self, security_code, authorizer: SMSAuthorizer):
4547
self.security_code = security_code
4648
self.authorizer = authorizer
47-
49+
4850
def pay(self, order):
4951
if not self.authorizer.is_authorized():
5052
raise Exception("Not authorized")
5153
print("Processing debit payment type")
5254
print(f"Verifying security code: {self.security_code}")
5355
order.status = "paid"
5456

57+
5558
class CreditPaymentProcessor(PaymentProcessor):
5659

5760
def __init__(self, security_code):
@@ -62,6 +65,7 @@ def pay(self, order):
6265
print(f"Verifying security code: {self.security_code}")
6366
order.status = "paid"
6467

68+
6569
class PaypalPaymentProcessor(PaymentProcessor):
6670

6771
def __init__(self, email_address, authorizer: SMSAuthorizer):
@@ -85,4 +89,4 @@ def pay(self, order):
8589
authorizer = SMSAuthorizer()
8690
# authorizer.verify_code(465839)
8791
processor = PaypalPaymentProcessor("[email protected]", authorizer)
88-
processor.pay(order)
92+
processor.pay(order)

9 - solid/interface-segregation-after.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from abc import ABC, abstractmethod
22

3+
34
class Order:
45

56
def __init__(self):
@@ -26,7 +27,8 @@ class PaymentProcessor(ABC):
2627
def pay(self, order):
2728
pass
2829

29-
class PaymentProcessor_SMS(PaymentProcessor):
30+
31+
class PaymentProcessorSMS(PaymentProcessor):
3032

3133
@abstractmethod
3234
def auth_sms(self, code):
@@ -36,7 +38,8 @@ def auth_sms(self, code):
3638
def pay(self, order):
3739
pass
3840

39-
class DebitPaymentProcessor(PaymentProcessor_SMS):
41+
42+
class DebitPaymentProcessor(PaymentProcessorSMS):
4043

4144
def __init__(self, security_code):
4245
self.security_code = security_code
@@ -45,14 +48,15 @@ def __init__(self, security_code):
4548
def auth_sms(self, code):
4649
print(f"Verifying SMS code {code}")
4750
self.verified = True
48-
51+
4952
def pay(self, order):
5053
if not self.verified:
5154
raise Exception("Not authorized")
5255
print("Processing debit payment type")
5356
print(f"Verifying security code: {self.security_code}")
5457
order.status = "paid"
5558

59+
5660
class CreditPaymentProcessor(PaymentProcessor):
5761

5862
def __init__(self, security_code):
@@ -63,7 +67,8 @@ def pay(self, order):
6367
print(f"Verifying security code: {self.security_code}")
6468
order.status = "paid"
6569

66-
class PaypalPaymentProcessor(PaymentProcessor_SMS):
70+
71+
class PaypalPaymentProcessor(PaymentProcessorSMS):
6772

6873
def __init__(self, email_address):
6974
self.email_address = email_address
@@ -89,4 +94,4 @@ def pay(self, order):
8994
print(order.total_price())
9095
processor = PaypalPaymentProcessor("[email protected]")
9196
processor.auth_sms(465839)
92-
processor.pay(order)
97+
processor.pay(order)

9 - solid/interface-segregation-before.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from abc import ABC, abstractmethod
22

3+
34
class Order:
45

56
def __init__(self):
@@ -30,6 +31,7 @@ def auth_sms(self, code):
3031
def pay(self, order):
3132
pass
3233

34+
3335
class DebitPaymentProcessor(PaymentProcessor):
3436

3537
def __init__(self, security_code):
@@ -39,14 +41,15 @@ def __init__(self, security_code):
3941
def auth_sms(self, code):
4042
print(f"Verifying SMS code {code}")
4143
self.verified = True
42-
44+
4345
def pay(self, order):
4446
if not self.verified:
4547
raise Exception("Not authorized")
4648
print("Processing debit payment type")
4749
print(f"Verifying security code: {self.security_code}")
4850
order.status = "paid"
4951

52+
5053
class CreditPaymentProcessor(PaymentProcessor):
5154

5255
def __init__(self, security_code):
@@ -60,6 +63,7 @@ def pay(self, order):
6063
print(f"Verifying security code: {self.security_code}")
6164
order.status = "paid"
6265

66+
6367
class PaypalPaymentProcessor(PaymentProcessor):
6468

6569
def __init__(self, email_address):
@@ -86,4 +90,4 @@ def pay(self, order):
8690
print(order.total_price())
8791
processor = DebitPaymentProcessor("2349875")
8892
processor.auth_sms(465839)
89-
processor.pay(order)
93+
processor.pay(order)

9 - solid/liskov-substitution-after.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from abc import ABC, abstractmethod
22

3+
34
class Order:
45

56
def __init__(self):
@@ -26,16 +27,18 @@ class PaymentProcessor(ABC):
2627
def pay(self, order):
2728
pass
2829

30+
2931
class DebitPaymentProcessor(PaymentProcessor):
3032

3133
def __init__(self, security_code):
3234
self.security_code = security_code
33-
35+
3436
def pay(self, order):
3537
print("Processing debit payment type")
3638
print(f"Verifying security code: {self.security_code}")
3739
order.status = "paid"
3840

41+
3942
class CreditPaymentProcessor(PaymentProcessor):
4043

4144
def __init__(self, security_code):
@@ -46,6 +49,7 @@ def pay(self, order):
4649
print(f"Verifying security code: {self.security_code}")
4750
order.status = "paid"
4851

52+
4953
class PaypalPaymentProcessor(PaymentProcessor):
5054

5155
def __init__(self, email_address):
@@ -64,4 +68,4 @@ def pay(self, order):
6468

6569
print(order.total_price())
6670
processor = PaypalPaymentProcessor("[email protected]")
67-
processor.pay(order)
71+
processor.pay(order)

9 - solid/liskov-substitution-before.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from abc import ABC, abstractmethod
22

3+
34
class Order:
45

56
def __init__(self):
@@ -20,25 +21,27 @@ def total_price(self):
2021
return total
2122

2223

23-
2424
class PaymentProcessor(ABC):
2525

2626
@abstractmethod
2727
def pay(self, order, security_code):
2828
pass
2929

30+
3031
class DebitPaymentProcessor(PaymentProcessor):
3132
def pay(self, order, security_code):
3233
print("Processing debit payment type")
3334
print(f"Verifying security code: {security_code}")
3435
order.status = "paid"
3536

37+
3638
class CreditPaymentProcessor(PaymentProcessor):
3739
def pay(self, order, security_code):
3840
print("Processing credit payment type")
3941
print(f"Verifying security code: {security_code}")
4042
order.status = "paid"
4143

44+
4245
class PaypalPaymentProcessor(PaymentProcessor):
4346
def pay(self, order, security_code):
4447
print("Processing paypal payment type")
@@ -53,4 +56,4 @@ def pay(self, order, security_code):
5356

5457
print(order.total_price())
5558
processor = PaypalPaymentProcessor()
56-
processor.pay(order, "[email protected]")
59+
processor.pay(order, "[email protected]")

0 commit comments

Comments
 (0)