-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadapter.py
More file actions
39 lines (34 loc) · 1.24 KB
/
Copy pathadapter.py
File metadata and controls
39 lines (34 loc) · 1.24 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
from src.structural.adapter.target import Target
from src.structural.adapter.adaptee import Adaptee
class Adapter(Target):
def __init__(self, adaptee: Adaptee):
self._adaptee = adaptee
def request(self) -> str:
return (
f"Adapter: (TRANSLATED) {self._adaptee.specific_request()[::-1]}"
)
# Example Usage:
# if __name__ == "__main__":
# adaptee = Adaptee()
# target = Adapter(adaptee)
# print(target.request())
#
# Output:
# Adapter: (TRANSLATED) Special behavior of the Adaptee.
# Common Mistakes to Avoid:
#
# 1. Misunderstanding Adapter's Role:
# - Mistake: Implementing business logic inside the adapter.
# - Fix: Keep the adapter focused only on translating interfaces.
#
# 2. Tight Coupling to the Adaptee:
# - Mistake: Directly exposing Adaptee methods in the Adapter.
# - Fix: Hide adaptee-specific logic from the client interface.
#
# 3. Violating Liskov Substitution Principle:
# - Mistake: Making Adapter behave differently than Target.
# - Fix: Ensure Adapter is substitutable for Target without side effects.
#
# 4. Ignoring Composition:
# - Mistake: Using inheritance when composition is more appropriate.
# - Fix: Favor composition over inheritance for more flexibility.