Skip to content

Commit 7bc70be

Browse files
committed
solutions
1 parent 28de4e3 commit 7bc70be

File tree

35 files changed

+989
-2715
lines changed

35 files changed

+989
-2715
lines changed

.github/workflows/labs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Run tests
2727
run: |
2828
cd 0_intro/01_hello
29-
pytest test_hello.py -v --tb=short
29+
pytest tests.py -v --tb=short
3030
3131
# ============================================
3232
# PRINCIPLES - GRASP
@@ -154,7 +154,7 @@ jobs:
154154
- name: Run tests
155155
run: |
156156
cd 2_creational/05_singleton
157-
pytest test_basic.py -v --tb=short
157+
pytest tests.py -v --tb=short
158158
159159
# ============================================
160160
# STRUCTURAL PATTERNS

0_intro/01_hello/solution.py

Lines changed: 0 additions & 68 deletions
This file was deleted.

0_intro/01_hello/starter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def add(a, b):
5151
Returns:
5252
Sum of a and b
5353
"""
54-
pass
54+
return a + b
5555

5656

5757
def multiply(a, b):
@@ -65,4 +65,4 @@ def multiply(a, b):
6565
Returns:
6666
Product of a and b
6767
"""
68-
pass
68+
return a * b
File renamed without changes.

1_principles/01_grasp/04_low_coupling/solution.py

Lines changed: 0 additions & 75 deletions
This file was deleted.

1_principles/01_grasp/04_low_coupling/starter.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ def save(self, player: str, score: int) -> str:
2828
# Metoda save_score(player, score) zwraca: "Saved score {score} for {player}"
2929

3030
class ScoreService:
31-
pass
31+
def __init__(self):
32+
self.database = Database()
33+
34+
def save_score(self, player: str, score: int) -> str:
35+
"""Pośrednik - izoluje Game od Database"""
36+
self.database.connect()
37+
return self.database.save(player, score)
3238

3339

3440
# TODO: Zaimplementuj Game
@@ -40,7 +46,14 @@ class ScoreService:
4046
# Low Coupling: Game nie zna Database, tylko ScoreService (pośrednik)
4147

4248
class Game:
43-
pass
49+
def __init__(self, score_service: ScoreService):
50+
"""Dependency Injection - redukuje sprzężenie"""
51+
self.score_service = score_service
52+
53+
def finish_game(self, player: str, score: int) -> str:
54+
"""Game używa tylko ScoreService, nie zna Database"""
55+
result = self.score_service.save_score(player, score)
56+
return f"Game finished. {result}"
4457

4558

4659
# GRASP Low Coupling:
@@ -55,8 +68,8 @@ class Game:
5568
# Korzyść: Zmiana Database nie wpływa na Game
5669

5770

58-
# Przykład użycia - odkomentuj gdy zaimplementujesz:
59-
# if __name__ == "__main__":
60-
# service = ScoreService()
61-
# game = Game(service)
62-
# print(game.finish_game("Alice", 150))
71+
# Przykład użycia
72+
if __name__ == "__main__":
73+
service = ScoreService()
74+
game = Game(service)
75+
print(game.finish_game("Alice", 150))

1_principles/02_solid/02_ocp/solution.py

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)