-
Notifications
You must be signed in to change notification settings - Fork 1
/
marilib_obj.py
109 lines (88 loc) · 3.38 KB
/
marilib_obj.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Jan 31 10:36 2020
@author: Nicolas Peteilh
"""
# --------------------------------------------------------------------------------------------------------------------------------
class AircraftFactory(object):
"""
Aircraft factory
"""
def __init__(self, name=None, engine_type="TF", engine_number=2):
self.name = name
self.engine_type = engine_type
self.engine_number = engine_number
def create_aircraft(self):
ac = Aircraft(engine_type=self.engine_type,
engine_number=self.engine_number)
if self.engine_type=="TF":
en = Turbofan(aircraft=ac)
elif self.engine_type=="TP":
en = Turboprop(aircraft=ac)
ac.engine = en
ac.total_thrust = ac.engine.compute_total_thrust()
return ac
# --------------------------------------------------------------------------------------------------------------------------------
class Aircraft(object):
"""
Assembling all aircraft data branches
"""
def __init__(self, name=None, engine_type=None, engine_number=None):
"""
Data structure branches, no ramification
"""
self.name = name
self.engine = None
self.engine_type = engine_type
self.engine_number = engine_number
self.total_thrust = None
# --------------------------------------------------------------------------------------------------------------------------------
class Engine(object):
"""
Assembling all aircraft data branches
"""
def __init__(self, name=None, aircraft=None):
"""
Data structure branches, no ramification
"""
self.name = name
self.aircraft = aircraft
def compute_thrust(self):
raise NotImplementedError
def compute_total_thrust(self):
return self.compute_thrust()*self.aircraft.engine_number
# --------------------------------------------------------------------------------------------------------------------------------
class Turbofan(Engine):
"""
Assembling all aircraft data branches
"""
def __init__(self, name=None, aircraft=None):
"""
J'ai déjà le name dans la classe mère donc je ne le rajoute pas là
Mais il faut peut-être ici rappeler __init__ de Engine pour ne pas l'écrase ? Si oui, on fait comment
"""
super(Turbofan, self).__init__(name,aircraft)
def compute_thrust(self):
print(self.name)
thrust = 9.0
return thrust
# --------------------------------------------------------------------------------------------------------------------------------
class Turboprop(Engine):
"""
Assembling all aircraft data branches
"""
# def __init__(self):
# """
# J'ai déjà le name dans la classe mère donc je ne le rajoute pas là
# Mais il faut peut-être ici rappeler __init__ de Engine pour ne pas l'écrase ? Si oui, on fait comment
# """
def compute_thrust(self):
thrust = 5.0
return thrust
if __name__ == "__main__":
usine_d_avion = AircraftFactory(name="CD_factory",
engine_number=3,
engine_type="TF")
avion = usine_d_avion.create_aircraft()
print("avion.total_thrust = ", avion.total_thrust)