ELENESSKI GAMES
  • Home
  • Games
    • Worzzler
    • The Lost Tribes
  • Unity
    • Facade Generator for Archimatix
    • Elenesski Object Database
    • Generic Move Camera
    • Unity C# Library
  • SQLINQ
    • Change Log
    • Concepts >
      • Overview
      • The Patterns
      • Database & Factories
      • Working with Tables
      • Custom Queries
      • Lazy Loading
      • Units of Work
    • Video Tutorials
    • Getting Started
    • Code Examples >
      • Implementing Behavior
      • Finding Objects
      • Custom Searches
      • Converters and Transformers
      • Object Association Management
      • New Objects
      • Creating Database
      • Associating Objects
      • Deleting Objects
      • Validating Objects
      • Saving
    • Sample Model >
      • Tutorial Model
      • Table Classes Code
      • Domain Classes Code
      • Factories Code
    • OSX Developers
    • Bridge Building
    • External Websites
    • Class Documentation
  • Presentations
    • 3D Ship Design
  • Music
    • Jamendo (Main)
    • Blend
    • Sound Cloud
    • Mixcloud (DJ)
    • DJ Demos
  • YouTube

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:
  1. Use the default constructor
  2. Use an initialzer
  3. 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.

Picture
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);