You can use the attribute [Domain
("new")] on an action parameter whenever a new object should appear. This is
covered in Section 15.2.
??? A static factory method called Create. This factory method is used instead of
C# operator new in contexts where a instance of T needs to be created within a
method. This is an advanced feature; most model programs will use the parameter
generator [Domain("new")] as a way to introduce new objects instead of the
Create factory method.
??? A virtual method Initialize. The model program should override this method
for type T and reset all instance fields to their initial state.
In the following sections we present some topics that relate to the use of LabeledInstance<
T> for object-oriented modeling.
15.2 Creating instances
Whenever you model objects, you have to deal with the issue of instantiation. How
do instances come into existence? How are they deleted?
For example, we might extend our employee example as follows with actions
that add and remove employees from the system. Here we program in an objectoriented
style, but without using LabeledInstance, managing the IDs and the field
map explicitly in our code.
250 Modeling Objects
namespace Payroll1
{
class Employee : CompoundValue
{
public readonly int id;
public Employee(int id) { this.id = id; }
}
static class Contract
{
static int nextId = 1;
static Set
allEmployees = Set.
Pages:
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332