-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcouplage.py
More file actions
44 lines (36 loc) · 1.12 KB
/
couplage.py
File metadata and controls
44 lines (36 loc) · 1.12 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
from abc import ABC, abstractmethod
class Individu:
def __ini__(self):
pass
# Interface pour découpler
class IndividuFactoryInterface(ABC):
@abstractmethod
def creer_individu(self):
pass
class IndividuFactoryHomme(IndividuFactoryInterface):
def creer_individu(self):
"""
Factory Method pour créer un individu
avec ses jambes déjà initialisées
"""
return Individu()
class IndividuFactoryFemme(IndividuFactoryInterface):
def creer_individu(self):
"""
Factory Method pour créer un individu
avec ses jambes déjà initialisées
"""
return Individu()
class Service:
def __init__(self, factory: IndividuFactoryInterface):
"""
Injection de dépendance pour faible couplage
Le Service ne dépend plus de la Factory concrète
"""
self.factory = factory
def traitement(self):
individu = self.factory.creer_individu()
service = Service(IndividuFactoryHomme())
individu1 = service.traitement();
service = Service(IndividuFactoryFemme())
individu2 = service.traitement();