You use objects in MDriven to work with the individual instances of the classes in your modelâfor example, one specific Person, Department, or Order.
Objects and classes
An object is an instance of a class. A class defines what objects of that kind can contain and do: their attributes, operations, and relationships to other classes.
For example, a model can define a Person class with Name and Age attributes. Each Person object has its own attribute values:
| Class | Object | Attribute values |
|---|---|---|
Person
|
One Person object | Name = 'Sandra', Age = 25
|
Person
|
Another Person object | Name = 'David', Age = 41
|
The class is the shared definition; the objects are the individual modeled entities that use that definition. For a fuller description of class structure and inheritance, see Documentation:Class.
What an object contains
An object has state through the values of its attributes. It can also participate in relationships with other objects through associations.
For example, if Person has an association to Department, a Person object can be linked to a Department object. The association describes the connection in the model; the link connects the particular objects.
Use an association when the relationship itself is all you need. If the relationship needs its own attributes or behavior, model it as an association class (also called a link object). See Documentation:Part 8 Link Objects association classes.
Objects, values, and OCL
OCL expressions can work with objects, their attributes, and collections of objects. For example, an expression may navigate from a Person object to related objects through an association, or select objects from a collection.
A value is an attribute value or expression result such as a number, Boolean value, or text. An object is an instance of a modeled class. Keep this distinction in mind when reading an operator's parameter requirements.
String is not an OCL object
In MDriven's OCL implementation, the String type is not an object. Therefore, where an OCL operator requires an object as a parameter, you cannot supply a String value.
For example, a Person object and its Name value are different kinds of expression results:
person -- an object
person.Name -- a String valueCheck the documentation for the specific OCL operator before passing a value to it.
Collections of objects
An OCL expression can return a collection of objects. Collection operators apply to that collection; see Documentation:OCL Collection Operators.
A collection can be a set or a bag:
| Collection type | Object occurrence rule |
|---|---|
| Set | Contains only one occurrence of each object; duplicate results are removed. |
| Bag | Can contain multiple occurrences of the same object. |
See Documentation:Set vs bag for examples and details.
Be careful with expressions that inspect loaded objects only. allLoadedObjects returns objects currently loaded in memory and does not load objects from the database, so its result depends on the current application state. See Documentation:OCLOperators allLoadedObjects.
Objects and persisted data
MDriven maps modeled classes and their objects to the underlying relational database through object-relational mapping. This lets you work with modeled objects and associations while the mapping connects them to stored data.
For imports, XmlToObjects can create objects that match structured XML data. For example, XML data containing a person's name and age can create a new Person object with those attribute values. See Documentation:OCLOperators XmlToObjects.
See also
- Documentation:Class
- Documentation:Association
- Documentation:Part 8 Link Objects association classes
- Documentation:OR Mapping
- Documentation:OCL Collection Operators
[[Category:Classes: definition and instances [Beginner]]
