LotSizingDataModel.Core 2.0.1
Core domain model, shared abstractions and XML-serializable entities.
Loading...
Searching...
No Matches
ComponentRequirement.cs
Go to the documentation of this file.
1using System;
2using System.Xml.Serialization;
4
6
7/// <summary>
8/// Represents a bill-of-materials relationship between two items.
9///
10/// A quantity of the component item j is required to manufacture
11/// one unit of the parent item i.
12///
13/// Corresponds to A[j,i] in the source model.
14/// </summary>
15[Serializable]
16[XmlType(TypeName = "componentRequirement")]
17public sealed class ComponentRequirement : ModelObject
18{
19 private int _parentItemId;
20 private int _componentItemId;
21 private int _quantity;
22
23 /// <summary>
24 /// Initializes an empty component requirement.
25 ///
26 /// This public parameterless constructor is required
27 /// by <see cref="XmlSerializer"/>.
28 /// </summary>
30 {
31 }
32
33 /// <summary>
34 /// Initializes a bill-of-materials relationship.
35 /// </summary>
36 /// <param name="parentItemId">
37 /// Identifier of the item being manufactured, corresponding to i.
38 /// </param>
39 /// <param name="componentItemId">
40 /// Identifier of the required component, corresponding to j.
41 /// </param>
42 /// <param name="quantity">
43 /// Quantity of component j required to manufacture one unit
44 /// of parent item i, corresponding to A[j,i].
45 /// </param>
47 int parentItemId,
48 int componentItemId,
49 int quantity)
50 {
51 // Initialize all properties (validation occurs in setters)
52 ParentItemId = parentItemId;
53 ComponentItemId = componentItemId;
54 Quantity = quantity;
55 }
56
57 /// <summary>
58 /// Gets or sets the identifier of the item being manufactured.
59 ///
60 /// Corresponds to index i in A[j,i].
61 /// </summary>
62 [XmlAttribute("parentItemId")]
63 public int ParentItemId
64 {
65 get => _parentItemId;
66 set
67 {
68 // Validate that the identifier is non-negative
69 if (value < 0)
70 {
71 throw new ArgumentOutOfRangeException(
72 nameof(value),
73 value,
74 "The parent item identifier cannot be negative.");
75 }
76
77 // Update the backing field and notify property change if value differs
78 SetProperty(ref _parentItemId, value);
79 }
80 }
81
82 /// <summary>
83 /// Gets or sets the identifier of the required component.
84 ///
85 /// Corresponds to index j in A[j,i].
86 /// </summary>
87 [XmlAttribute("componentItemId")]
88 public int ComponentItemId
89 {
90 get => _componentItemId;
91 set
92 {
93 // Validate that the identifier is non-negative
94 if (value < 0)
95 {
96 throw new ArgumentOutOfRangeException(
97 nameof(value),
98 value,
99 "The component item identifier cannot be negative.");
100 }
101
102 // Update the backing field and notify property change if value differs
103 SetProperty(ref _componentItemId, value);
104 }
105 }
106
107 /// <summary>
108 /// Gets or sets the quantity of the component required
109 /// to manufacture one unit of the parent item.
110 ///
111 /// Corresponds to A[j,i] in the source model.
112 /// </summary>
113 [XmlAttribute("quantity")]
114 public int Quantity
115 {
116 get => _quantity;
117 set
118 {
119 // Validate that the quantity is non-negative
120 if (value < 0)
121 {
122 throw new ArgumentOutOfRangeException(
123 nameof(value),
124 value,
125 "The component quantity cannot be negative.");
126 }
127
128 // Update the backing field and notify property change if value differs
129 SetProperty(ref _quantity, value);
130 }
131 }
132}
Base class for model objects that notify listeners when one of their properties changes.
int ParentItemId
Gets or sets the identifier of the item being manufactured.
ComponentRequirement(int parentItemId, int componentItemId, int quantity)
Initializes a bill-of-materials relationship.
int ComponentItemId
Gets or sets the identifier of the required component.
ComponentRequirement()
Initializes an empty component requirement.
int Quantity
Gets or sets the quantity of the component required to manufacture one unit of the parent item.