====== 5.3 Objects ====== [[dido:public:s_cli:05_contents:01_prt:04_dll:start| Return to DidoDLL]] ===== Purpose ===== [[dido:public:s_cli:05_contents:01_prt:06_dddl:objects| Return to Top]] ===== Syntax ===== [[dido:public:s_cli:05_contents:01_prt:06_dddl:objects| Return to Top]] DEFINE OBJECT AS ( { : [ NULL | NOT NULL] [ TOKEN | ""] [:= ==== Where ==== * **ObjectName** The ObjectName can be qualified with a namespace by using periods (i.e., '.') within the name. Eachlanespaces and the ObjectName are limited to 30 characters in length. ObjectName ::= textual name associated with the Object. * **AttributeName** The AttributeName can not be associated with a namespace and is limited to 30 characters in length. AttributeName ::= textual name associated with the Attribute. * **DataType** The Data Type can be on of the or a Type created within the DIDO. DataType ::= textual name of the Data Type associated with the attribute. * **InitialValue (Optional)** The initial values are those required by the specific Data Type. For example, the GeoPosition requires three parameters (Lat, Long and Elevation). When multiple values are required, th values need to be surrounded by parenthesis. InitialValue ::= An expression that is used to initialize the attribute value. === Examples === -- Setup some domain specific types to use when creating DIDO objects --- PersonNameType DEDFINE TYPE PersonNameType ( value : IN Text NOT NULL NOT EMPTY ) AS TEXT WITH CONSTRAINTS ( DEFAULT = NULL, COMPRESION = ONE, CASE = TITLE, MAX_LENGTH = 30, VALUE = value ); --- IdType DEFINE TYPE IdType ( algorithm : IN Text NOT NULL NOT EMPTY := DEFAULT_ALGORITHM message : IN Text NOT NULL NOT EMPTY := CURRENT_DATE, options : IN Text := "Hex" ) AS HASH WITH CONSTRAINTS ( DEFAULT = algorithm, MESSAGE = message, OPTIONS = options ); --- Create an object that doesn't have any tokens in it DEFINE OBJECT MyDido.Student ( firstName : IN PersonNameType NOT NULL NOT EMPTY, lastName : IN PersonNameType NOT NULL NOT EMPTY ) RETURN IdType AS ( StudentId : IdType RETURN := NEW IdType ( message = FirstName + LastName), FirstName : PersonNameType := firstName, LastName : PersonNameType := lastName ); --- Setup some domain specific constants to use when creating objects DEFINE CONSTANT DEFAULT_CURRENCY_SYMBOL AS 'ยง'; DEFINE CONSTANT DEFAULT_CURRENCY_NAME AS "StudentCoin"; --- Create a type that describes the Student Coin DEFINE TYPE SudentCoinType ( initialBalance : IN FIXED NOT NULL := 0.00, currencyName : IN Text NOT NULL NOT EMPTY := DEFAULT_CURRENCY_NAME, currencySymbol : IN Text NOT NULL NOT EMPTY := DEFAULT_CURRENCY_SYMBOL, precision : IN Text NOT NULL NOT EMPTY := "5,2", min : IN FIXED NOT NULL := -50.00, max : IN FIXED NOT NULL := 1000.00 ) AS FIXED ALLOWING NONULL WITH CONSTRAINTS ( MIN = min, MAX = max, VALUE = initialBalance, UNITS = currencyName, SYMBOL = currencySymbol, PRECISION = precision ); --- Create a Student Account that uses the StudentCoinType to track a balance. --- The Balance is also a TOKEN which marks the value as requiring a Transaction --- to prevent "Double Spend" CREATE OBJECT OurDido.StudentAccount ( studentId : IdType NOT NULL, balance : SudentCoinType NOT NULL ) RETURN AS IdType AS ( AccountId : IdType RETURN := NEW IdType ( message = studentId + balance), StudentId : IdType := studentId, Balance : SudentCoinType TOKEN := balance ); /**=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- /* To add a discussion page to this page, comment out the line that says ~~DISCUSSION:off~~ */ ~~DISCUSSION:on|Outstanding Issues~~ ~~DISCUSSION:off~~