-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfactory.py
More file actions
40 lines (33 loc) · 1019 Bytes
/
factory.py
File metadata and controls
40 lines (33 loc) · 1019 Bytes
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
from abc import ABC, abstractmethod
# Interface Transport
class Transport(ABC):
@abstractmethod
def livrer(self):
pass
# Classe Bateau
class Bateau(Transport):
def livrer(self):
return "Livraison par bateau"
# Classe Camion
class Camion(Transport):
def livrer(self):
return "Livraison par camion"
class TransportFactoryInterface(ABC):
@abstractmethod
def get_transport(type_transport):
pass
class TransportFactory(TransportFactoryInterface):
@staticmethod
def get_transport(type_transport):
if type_transport == "bateau":
return Bateau()
elif type_transport == "camion":
return Camion()
else:
raise ValueError(f"Type de transport inconnu : {type_transport}")
# Exemple d'utilisation
if __name__ == "__main__":
transport1 = TransportFactory.get_transport("bateau")
print(transport1.livrer())
transport2 = TransportFactory.get_transport("camion")
print(transport2.livrer())