You use an attribute in MDriven Designer to describe a scalar piece of information about an object, such as an employee's name, salary, or birth date.
What an attribute represents
An attribute is a property of a class in your model. It holds a value of a basic data type, such as text, a number, or a date.
For example, an Employee class can have these attributes:
| Attribute | Example value | Meaning |
|---|---|---|
Name
|
"Ava Nilsson"
|
The employee's name |
EmployeeId
|
"E-1042"
|
An identifier for the employee |
Salary
|
45000
|
The employee's salary |
BirthDate
|
A date value | The date used to determine the employee's age |
Attributes define the information that a class carries. When an attribute is persisted, it also contributes to the database structure created or evolved from the model.
Choose the right kind of attribute
Choose the attribute kind based on where the value comes from, whether it must be stored, and whether users or actions must be able to set it.
| Kind | Use it when | Example |
|---|---|---|
| Persisted attribute | The value is part of the object's stored state and must be saved in the database. | Employee.Name and Product.Price
|
| Transient attribute | The value is needed in memory but must not be stored. It is lost when the user session ends. | A temporary value used while the user works with an object |
| Derived attribute | The value can be calculated from other values with an OCL expression. | Age, calculated from BirthDate
|
| Derived settable attribute | You need a calculated value that can also accept input and write that input back to its source attributes through an EAL expression. | An attribute that displays a value derived from other attributes and updates those source attributes when it is set |
Persisted attributes
A persisted attribute represents basic data that MDriven stores automatically in the database. Use it for information that must remain available after the object and user session are no longer in memory.
For example, store Product.Price as a persisted attribute when the price is part of the product record.
When you add or change persisted attributes in an existing database, consider nullability and database defaults. A non-nullable attribute generally needs a database default when the database is evolved, because existing rows need a value. See Documentation:Initial values and Default Database values and Documentation:DefaultDBValue.
Transient attributes
A transient attribute has a basic data type but is kept only in memory. MDriven does not store it in the database, and its value is lost when the user session ends.
For example, use a transient attribute for a temporary value that is relevant while a user works with an Employee object but should not become part of the employee record.
Derived attributes
A derived attribute calculates its value from other model values using OCL. The attribute does not become an independent stored copy of the calculated value.
For example, an Employee.Age attribute can derive its value from Employee.BirthDate. The source value remains BirthDate; Age is the calculated representation.
Derived attributes are also useful when you want to test a new representation or transformation without changing existing persisted data. For example, you can introduce a derived decimal price based on an existing integer price while you evaluate a conversion. For conversion approaches and implications, see Documentation:Attribute or Data Type Conversion.
Derived settable attributes
A derived settable attribute has both:
- an OCL expression that calculates the value to read, and
- an EAL expression that writes a supplied value back to the source attributes.
Use this kind only when you can define how an entered value updates the values from which it is derived. Unlike a regular derived attribute, it supports writing through the derived representation.
Attributes and associations
An attribute holds a basic value. It does not represent a link to another modeled class.
For example, Employee.Name is an attribute because it holds text. An employee's link to a Department object is an association, because it is an object reference. MDriven therefore does not allow an attribute with a class type; model that relationship as an association instead. See Documentation:Attribute with class type.
Design and data considerations
Set appropriate string lengths
Make string attributes long enough for the values you intend to save. Saving text that exceeds an attribute's database length can cause a String or binary data would be truncated error.
For example, if an error-message attribute can receive long server-side error text, define sufficient length and ensure code does not write more text than the attribute allows. See Documentation:String attribute overflowing.
Use delayed fetch for large attribute values
When an attribute can contain a large amount of data and you do not need it whenever its object is loaded, set DelayedFetch to true. MDriven then fetches the attribute when it is accessed rather than when its containing object is loaded. See Documentation:Delayed Fetch.
Check whether a value has changed
In OCL, you can use IsDirtyMember on a class attribute to determine whether that attribute has changes pending to be saved. See Documentation:OCLOperators IsDirtyMember.
See also
- Documentation:Attribute with class type
- Documentation:Initial values and Default Database values
- Documentation:Attribute or Data Type Conversion
- Documentation:Delayed Fetch
- Documentation:String attribute overflowing
[[Category:Attributes and data types [Beginner]]]
