Bonjour,
N'ayant pas l'habitude des classes, j'aurais besoin d'avis.
Je viens de réaliser des classes et je voudrais savoir si tout semble correct, ce qui peut être amélioré et pourquoi.
Merci de votre aide.
Exemple d'utilisation
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Dim a As New AdaptationLogement(New AdaptationLogement.Logement(1, 1, 1), 14, 100) a.Logements.Add(New AdaptationLogement.Logement(2, 2, 1)) a.Logements.Add(New AdaptationLogement.Logement(3, 2, 1)) a.Logements.Add(New AdaptationLogement.Logement(4, 3, 2)) a.Logements.Add(New AdaptationLogement.Logement(5, 3, 2)) a.Logements.Add(New AdaptationLogement.Logement(6, 4, 2)) a.Logements.Add(New AdaptationLogement.Logement(7, 4, 2)) a.Logements.Add(New AdaptationLogement.Logement(8, 4, 2)) Dim montantOs As Decimal = a.Montant Dim montantMaille1 As Decimal = a.MontantMaille(1) Dim montantMaille2 As Decimal = a.MontantMaille(2) Dim montantBat1 As Decimal = a.MontantBatiment(1) Dim montantBat2 As Decimal = a.MontantBatiment(2) Dim montantBat3 As Decimal = a.MontantBatiment(3) Dim montantBat4 As Decimal = a.MontantBatiment(4) Dim b As New AdaptationLogement(15, 500) b.Logements.Add(New AdaptationLogement.Logement(10, 5, 5)) b.Logements.Add(New AdaptationLogement.Logement(11, 6, 5)) b.Logements.Add(New AdaptationLogement.Logement(12, 6, 5)) Dim z As New AdaptationLogementCollection() z.Add(a) z.Add(b) Dim total As Decimal = z.Somme Dim totalBat As Decimal = z.SommeBatiment(2) Dim totalMail As Decimal = z.SommeMaille(4) Dim m As New AdaptationOuvrage(77, 250) m.Maille.Add(New AdaptationOuvrage.OuvrageMaille(2, 5)) m.Maille.Add(New AdaptationOuvrage.OuvrageMaille(3, 10)) Dim n As New AdaptationOuvrage(770, 1000) n.Maille.Add(New AdaptationOuvrage.OuvrageMaille(3, 8)) Dim TotalOuv_m = m.Montant() Dim TotalOuvMaille = m.MontantMaille(3) Dim macollectOuv As New AdaptationOuvrageCollection macollectOuv.Add(m) macollectOuv.Add(n) Dim sommeMaille3 = macollectOuv.SommeMaille(3)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288 Public MustInherit Class Adaptation Private _mIdAdaptation As Long Public Property IdAdaptation() As Long Get Return _mIdAdaptation End Get Set(ByVal value As Long) _mIdAdaptation = value End Set End Property Private _mForfait As Decimal Public Property Forfait() As Decimal Get Return _mForfait End Get Set(ByVal value As Decimal) _mForfait = value End Set End Property Public Sub New(ByVal idAdaptation As Long, ByVal forfait As Decimal) If idAdaptation <= 0 Then Throw New ArgumentNullException("idAdaptation", "Identifiant non défini.") _mIdAdaptation = idAdaptation _mForfait = forfait End Sub End Class Public Class AdaptationLogement Inherits Adaptation Structure Logement Private _mIdLogement As Long Public ReadOnly Property idLogement() As Long Get Return _mIdLogement End Get End Property Private _mIdBatiment As Long Public ReadOnly Property idBatiment() As Long Get Return _mIdBatiment End Get End Property Private _mIdMaille As Long Public ReadOnly Property idMaille() As Long Get Return _mIdMaille End Get End Property Public Sub New(ByVal idLogement As Long, ByVal idBatiment As Long, ByVal idMaille As Long) _mIdLogement = idLogement _mIdBatiment = idBatiment _mIdMaille = idMaille End Sub End Structure Private _mLogement As List(Of Logement) = New List(Of Logement) Public Property Logements() As List(Of Logement) Get Return _mLogement End Get Set(ByVal value As List(Of Logement)) _mLogement = value End Set End Property Public Sub New(ByVal idAdaptation As Long, ByVal forfait As Decimal) MyBase.New(idAdaptation, forfait) End Sub Public Sub New(ByVal logement As Logement, ByVal idAdaptation As Long, ByVal forfait As Decimal) MyBase.New(idAdaptation, forfait) _mLogement.Add(logement) End Sub Public Function Montant() As Decimal Return Forfait * Logements.Count End Function Public Function MontantBatiment(ByVal idBatiment As Long) As Decimal Dim nbLogt As Integer = Logements.Count Dim nbLogtBat As Integer = 0 For i As Integer = 0 To nbLogt - 1 If Logements(i).idBatiment = idBatiment Then nbLogtBat += 1 Next Return Forfait * nbLogtBat End Function Public Function MontantMaille(ByVal idMaille As Long) As Decimal Dim nbLogt As Integer = Logements.Count Dim nbLogtMaille As Integer = 0 For i As Integer = 0 To nbLogt - 1 If Logements(i).idMaille = idMaille Then nbLogtMaille += 1 Next Return Forfait * nbLogtMaille End Function End Class Public Class AdaptationOuvrage Inherits Adaptation Structure OuvrageMaille Private _mIdMaille As Long Public ReadOnly Property IdMaille() As Long Get Return _mIdMaille End Get End Property Private _mNbOuvrage As Integer Public ReadOnly Property NbOuvrage() As Integer Get Return _mNbOuvrage End Get End Property Public Sub New(ByVal idMaille As Long, ByVal nbOuvrage As Integer) If idMaille <= 0 Then Throw New ArgumentNullException("idMaille", "Identifiant non défini.") If nbOuvrage < 0 Then Throw New ArgumentOutOfRangeException("nbOuvrage", "valeur incorrect.") _mIdMaille = idMaille _mnbOuvrage = nbOuvrage End Sub End Structure Private _mMaille As List(Of OuvrageMaille) = New List(Of OuvrageMaille) Public Property Maille() As List(Of OuvrageMaille) Get Return _mMaille End Get Set(ByVal value As List(Of OuvrageMaille)) _mMaille = value End Set End Property Public Sub New(ByVal idAdaptation As Long, ByVal forfait As Decimal) MyBase.New(idAdaptation, forfait) End Sub Public Function Montant() As Decimal Dim nbMaille As Integer = Maille.Count Dim total As Decimal = 0 For i As Integer = 0 To nbMaille - 1 total += Forfait * Maille(i).NbOuvrage Next Return total End Function Public Function MontantMaille(ByVal idMaille As Long) As Decimal Dim nbMaille As Integer = Maille.Count Dim total As Decimal = 0 For i As Integer = 0 To nbMaille - 1 If Maille(i).IdMaille = idMaille Then total += Forfait * Maille(i).NbOuvrage Next Return total End Function End Class Public Class AdaptationLogementCollection Inherits CollectionBase Default Public Property Item(ByVal index As Integer) As AdaptationLogement Get Return DirectCast(List.Item(index), AdaptationLogement) End Get Set(ByVal value As AdaptationLogement) List.Item(index) = value End Set End Property Public Sub Add(ByVal value As AdaptationLogement) List.Add(value) End Sub Public Sub Remove(ByVal value As AdaptationLogement) List.Remove(value) End Sub Public Function Somme() Dim total As Decimal = 0 Dim nbElement As Integer = Me.List.Count Dim AdaptationLogement As AdaptationLogement For i As Integer = 0 To nbElement - 1 AdaptationLogement = Me.List.Item(i) total += AdaptationLogement.Montant Next Return total End Function Public Function SommeBatiment(ByVal idBatiment As Long) Dim total As Decimal = 0 Dim nbElement As Integer = Me.List.Count Dim AdaptationLogement As AdaptationLogement For i As Integer = 0 To nbElement - 1 AdaptationLogement = Me.List.Item(i) total += AdaptationLogement.MontantBatiment(idBatiment) Next Return total End Function Public Function SommeMaille(ByVal idMaille As Long) Dim total As Decimal = 0 Dim nbElement As Integer = Me.List.Count Dim AdaptationLogement As AdaptationLogement For i As Integer = 0 To nbElement - 1 AdaptationLogement = Me.List.Item(i) total += AdaptationLogement.MontantMaille(idMaille) Next Return total End Function End Class Public Class AdaptationOuvrageCollection Inherits CollectionBase Default Public Property Item(ByVal index As Integer) As AdaptationOuvrage Get Return DirectCast(List.Item(index), AdaptationOuvrage) End Get Set(ByVal value As AdaptationOuvrage) List.Item(index) = value End Set End Property Public Sub Add(ByVal value As AdaptationOuvrage) List.Add(value) End Sub Public Sub Remove(ByVal value As AdaptationOuvrage) List.Remove(value) End Sub Public Function Somme() As Decimal Dim nbElement As Integer = List.Count Dim AdaptationOuvrage As AdaptationOuvrage Dim total As Decimal = 0 For i As Integer = 0 To nbElement - 1 AdaptationOuvrage = List(i) total += AdaptationOuvrage.Montant() Next Return total End Function Public Function SommeMaille(ByVal idMaille) As Decimal Dim nbElement As Integer = List.Count Dim AdaptationOuvrage As AdaptationOuvrage Dim total As Decimal = 0 For i As Integer = 0 To nbElement - 1 AdaptationOuvrage = List(i) total += AdaptationOuvrage.MontantMaille(idMaille) Next Return total End Function End Class
Partager