CreAting and inserting objects
When objects come out of the database SQLINQ automatically assigns all the right attributes so that you are seeing what was stored for them in the database.
When constructing objects you have one of three options:
For this discussion consider this class diagram, with NebulaObject the item we'll be creating. SpaceObject is in italics which means, in UML notation, that the class is abstract. This means it can never be constructed into a real object.
When constructing objects you have one of three options:
- Use the default constructor
- Use an initialzer
- Use assignments
For this discussion consider this class diagram, with NebulaObject the item we'll be creating. SpaceObject is in italics which means, in UML notation, that the class is abstract. This means it can never be constructed into a real object.
Default Constructor
Every object in the system creates a default constructor. It's used by the object creation platform when items are loaded out of the database. When creating any one of these objects, use 0 for all OIDs. Review the section on Associating objects to learn how to associate objects together.
Default Constructors are always the recommended strategy for dealing with objects. It's the only way to guarantee that all attributes of an object are property assigned upon construction. Initializers and Assignments, set whatever you want, but run the risk that as you object model evolves, you run the risk of not assigning a critical attribute and this leads to bugs and rework.
NebulaObject myNebulaObject= new NebulaObject(0
, false
, ""
, UnityEngine.Random.Range(-2000000000, 2000000000)
, OBJECT.Location.x + OBJECT.Offset.x
, OBJECT.Location.y + OBJECT.Offset.y
, OBJECT.Offset.z
, Guid.NewGuid()
, OBJECT.Radius
, UnityEngine.Random.Range(0.3f, 1f) );
Initializer
An initialzer is similar to a constructor, except you list all the attributes by name that you want to initialize as part of the construction process. It allow the parameter order of the constructor to change without affecting how you construct it.
myNebulaObject = new NebulaObject(0) {
isDiscovered = false
, Name = ""
, Seed = UnityEngine.Random.Range(-2000000000, 2000000000)
, SectorX = OBJECT.Location.x + OBJECT.Offset.x
, SectorY = OBJECT.Location.y + OBJECT.Offset.y
, SectorZ = OBJECT.Offset.z
, OrbitalIdentifier = Guid.NewGuid()
, Radius = OBJECT.Radius
, Density = UnityEngine.Random.Range(0.3f, 1f)
};
Assignments
Assignments is the direct assignment of an attribute in code. You construct an object with a "0" parameter, then assign attribute values on the fly.
myNebulaObject = new NebulaObject(0);
myNebulaObject.isDiscovered = false;
myNebulaObject.Name = "";
myNebulaObject.Seed = UnityEngine.Random.Range(-2000000000,2000000000);
myNebulaObject.SectorX = OBJECT.Location.x + OBJECT.Offset.x;
myNebulaObject.SectorY = OBJECT.Location.y + OBJECT.Offset.y;
myNebulaObject.SectorZ = OBJECT.Offset.z;
myNebulaObject.OrbitalIdentifier = Guid.NewGuid();
myNebulaObject.Radius = OBJECT.Radius;
myNebulaObject.Density = UnityEngine.Random.Range(0.3f, 1f);
Every object in the system creates a default constructor. It's used by the object creation platform when items are loaded out of the database. When creating any one of these objects, use 0 for all OIDs. Review the section on Associating objects to learn how to associate objects together.
Default Constructors are always the recommended strategy for dealing with objects. It's the only way to guarantee that all attributes of an object are property assigned upon construction. Initializers and Assignments, set whatever you want, but run the risk that as you object model evolves, you run the risk of not assigning a critical attribute and this leads to bugs and rework.
NebulaObject myNebulaObject= new NebulaObject(0
, false
, ""
, UnityEngine.Random.Range(-2000000000, 2000000000)
, OBJECT.Location.x + OBJECT.Offset.x
, OBJECT.Location.y + OBJECT.Offset.y
, OBJECT.Offset.z
, Guid.NewGuid()
, OBJECT.Radius
, UnityEngine.Random.Range(0.3f, 1f) );
Initializer
An initialzer is similar to a constructor, except you list all the attributes by name that you want to initialize as part of the construction process. It allow the parameter order of the constructor to change without affecting how you construct it.
myNebulaObject = new NebulaObject(0) {
isDiscovered = false
, Name = ""
, Seed = UnityEngine.Random.Range(-2000000000, 2000000000)
, SectorX = OBJECT.Location.x + OBJECT.Offset.x
, SectorY = OBJECT.Location.y + OBJECT.Offset.y
, SectorZ = OBJECT.Offset.z
, OrbitalIdentifier = Guid.NewGuid()
, Radius = OBJECT.Radius
, Density = UnityEngine.Random.Range(0.3f, 1f)
};
Assignments
Assignments is the direct assignment of an attribute in code. You construct an object with a "0" parameter, then assign attribute values on the fly.
myNebulaObject = new NebulaObject(0);
myNebulaObject.isDiscovered = false;
myNebulaObject.Name = "";
myNebulaObject.Seed = UnityEngine.Random.Range(-2000000000,2000000000);
myNebulaObject.SectorX = OBJECT.Location.x + OBJECT.Offset.x;
myNebulaObject.SectorY = OBJECT.Location.y + OBJECT.Offset.y;
myNebulaObject.SectorZ = OBJECT.Offset.z;
myNebulaObject.OrbitalIdentifier = Guid.NewGuid();
myNebulaObject.Radius = OBJECT.Radius;
myNebulaObject.Density = UnityEngine.Random.Range(0.3f, 1f);