Classes

    Classes, the types for objects, are defined in the business model. A class may contain attributes, operations, and links (which may be attached to association classes). Note that in Xion each user-defined class has OclObject and OclAny as supertype.

 

    Object instanciation

    An object is instance of a class. new is the operator to create an object, followed by the name of the class of the new object, and then, between parenthesis, parameters of the called constructor. If the class does not define any constructor, parameters are empty.

For instance:

    An inexistent object is given by the null constant.

    An object is removed (from the database) by the predefined operation delete.

 

    Field names

     In the business model, names of packages, classes or fields (attributes, links or operations) , may contain white spaces. Xion does not support them, so they are replaced by the character _. For instance, a class named Hello Writer, in the package named Business Model, is called in Xion by Business_Model::Hello_Writer.

 

    Package indirection

    A class always belongs to a package, and a package may belong to another package. The Xion indirection separator is ::, just like / in an url, comparing files to classes and directories to packages. For instance, to access the Field class in package reflect of package lang, you must call lang::reflect::Field.

    It is not always necessary to give the full path for a class (called "absolute" path), in that a "relative" path may be enough. For instance, if the previous defined Field class is necessary in the Attribute class in the same package, calling Field is enough. In a method of the class Class of the package lang, just type reflect::Field.

 

    Field access

    A class is composed of field. Fields are attributes, links or operations. Each of them has a particular visibility, public, protected or private.

    The operator . allows field access. For instance, for an object in the variable o instance of the class A defining the public operation op(), calling op() on o is made by o.op()

    Warning: do not call any field on the null object !

 

    Static field access

    A class may define static fields. Static means that a field belongs to a class and not a particular object, i.e. its value is shared by each instance of the class. There are two access modes:

    The visibility attribute previously described are still valid.

 

    Attributes

    An attribute is a field with a given name and a Xion predefined type. It may be initialized into a constructor. By default, an attribute has the default value of its type.

 

    Operations

    An operation is a field with a name, a sequence of parameters (named and typed), and a return type. An operation is implemented by some methods (i.e. its behavior is described by a method) thanks to a text in Xion. An operation call is made giving its name, and then (between parenthesis) the value of transmitted parameters separated by comas. A method will access these parameters just as variables, thanks to their names. Parameters are passed by value, modifications made to variables with primitive types are not propagated outside the called method, however modifications made to objects are propagated since a variable of a parameter is a reference to an object.

 

    Overriding and virtuality

    It is possible to override methods. When an operation is called, the message is sent to the object (and not the class). For instance, the operation op() is defined in a class A. This operation is implemented by a method in A, overridden by a method in a child class B. In this code, the method defined in B is called:
    A myA = new B(); //possible thanks to type conformance
    my.op();

    This "virtuality" may be broken by the hard casting of the function oclAsType in the predefined type OclAny. In that each class defined in the business model inherits of OclAny, this property can be called on each business object casting it hardly. In the above example, instead of calling myA.op() would be coded myA.oclAsType(A).op(), the method op() of the A class is called. Of course, the real type of myA is always B. A simple cast like ((A)myA).op() would have called the method op() of B.

 

    Links

    A link is a field that associate a class to another one. A single link is equivalent to an attribute with a class type. Accessing a link is possible thanks to its role name. If there is no role name defined, and if the class of the link starts with an uppercase letter, the role name is given by the name of its class starting with a lowercase letter. Else, the link is inaccessible.

    If the association describing the link is not navigable in each directions, the link is not visible from each base class.

    For instance, consider an association between the A class and the B class. If the association has a multiplicity of 1 B, calling the link from an object of the A class is an expression of type B. For a multiplicity of 1..* or 0..*, or every multiplicity that define more than one maximum links, the above expression would have returned a Set(B). In case of the multiplicity 0..1, the expression has type B, but may be interpreted in a Set(B).

    To define a link with a maximum multiplicity 1, an affectation is enough (depending on the access rights...). It is possible to affect null. Add and remove operations exist for more important multiplicities, suffixed by the name of the link. It is not possible to give a null value to a link. It is possible to affect a collection to a link of multiplicity over 1.

Example:

Person father = new Person();
Person mother = new Person();
father.wife = mother;
/*equivalent to mother.husband = father; operations addwife and removewife do not exist*/
Person p = new Person();
//A man
p.addparent(father);
/*affectation of one of the parents of p; multiplicity 2: the predefined operation addparent is necessary*/
p.addparent(mother);
/*these two last lines are equivalent to p.parent = Set{father, mother};*/
Principal_House pricipalHouse = p.principal_House;
Set(Person) parents = p.parent;
Set(Person) children = p.children;
Person wife = p.wife;
//null if p is not married !
Boolean isMarried = p.wife->notEmpty;
/*notEmpty is a predefined operation of Collection; p.wife is a  Set(Person)*/
principalHouse.person;
//This is an error because of the navigation

 

    To an association class

    An association class is a class describing a link. It is necessary that its name starts with an uppercase letter. Access to the linked association class is possible thanks to its name starting with a lowercase letter. The result is an expression of the association class type, as described in the links paragraph. In case of association class, you cannot affect directly links, or use add predefined operations; but remove and affectation to null are allowed. To create the link affect the ones of the association object (see From an association class).

 

    From an association class

    Linked classes are accessed from the association class as described in the links paragraph. An association object describes a single link, so linked objects are always unique (or null). Affecting linked objects will instanciate links between them.

 

Previous    Summary    Next