Entitymodelstudio series tutorial 4-Advanced Static Modeling

Source: Internet
Author: User

This articleArticleThe content mainly describes some concepts related to static models and new content of emstudio. Correct and complete understanding of related concepts is helpful for developers to complete model design. Since emstudio has cropped and simplified the UML standard, these concepts are easy to understand and understand.

I.Three basic relationships

Three basic relationships used in static modeling are: Association, aggregation, and composition ). The following describes the three relationships in the static emstudio model.

Link:

Associations can be used to represent any relationship between two entities. When two entities need to be identified or have a certain link between them, they can be expressed by associations. Of course, the existing relationships do not need to be identified, and whether or not they depend on the designer. Generally, the measurement is identified only when the current static model needs to be processed or belongs to the problem domain of the current static model. You can also create and mark a non-existent link. The determination depends on whether the static model can be better described and designed as a scale.

In general, an association is a loose relationship that has no constraints on both parties. It only identifies the existence of such a relationship. In the static model of emstudio, the Association relation does not have any other semantics, so no additional operations are performed on the association. Association is only a tool that correctly and appropriately describes models. It helps developers understand and understand static models.

Aggregation relationship:

First, an aggregation link is an association link, but an aggregation link also has other semantics that the association link does not have. These semantics are embodied in the following Conveniences:

1.Source codeAspect

Aggregation link in SourceCodeIs embodied by Link Attributes, that is, the aggregation relationship is represented as an attribute in the principal object of the link.

2.Different responsibilities

In the aggregation relationship, the principal entity is active and bears more responsibilities. Generally, it can be defined as an aggregation relationship. A payer entity is often an integral part or a member of the principal entity. For example, the relationship between House entities and window entities, and between company entities and employee entities.

3.Data Operations

When emlib performs cascade activation, the payer entity of the aggregation relationship is also activated. However, whether this operation is executed depends on the value of the minor options-active attribute of the link. The value of this attribute can be modified in the Entity Designer. Note that after a new link is created, the default value of this attribute is false, that is, the cascade activation of the payer entity is not performed.

Combination:

First, the composite relationship is an aggregation relationship. The difference between the two is that the principal entity of the composite relationship also needs to be responsible for the lifecycle of the relational payer entity. That is to say, when the primary entity is destroyed, the compound entity must be destroyed. This Semantics is understood at the source code level and corresponds to the actual world. It can be considered that a composite relationship is closer than an aggregate relationship. For example, the house and window mentioned in the above example are in an integral and partial relationship, expressed by aggregation. The relationship between people and the heart is also a part of the relationship with the whole, but this relationship can be expressed by a combination to emphasize the closeness between the two. Of course, the scale of these judgments is not absolute, and whether they are closely understood can be different. Therefore, the model designer should decide which link to use to design the model.

In terms of database operations, when emlib executes the cascade delete operation, the payer entity of the composite link is also deleted. However, whether this operation is executed depends on the value of the minor options-delete attribute of the link. The value of this attribute can be modified in the Entity Designer. Note that after a new link is created, the default value of this attribute is false, that is, the cascade deletion of the payer object is not performed.

II.Homogeneous relationships, container entities and homogeneous entities

This part of content is the extension of emstudio to the static model. First, explain what is an homogeneous relationship. When we need to store data of different entities in the same data table, we need to use homogeneous relationships. For example, if the data of Entity A and entity B is to be stored in the same data table C, the designer can define entities A, B, and entity C in A, C, and entity B, c defines homogeneous relationships and makes C the principal party of the relationships. At this time, the principal of the link is called the container entity, and the principal of the link is called the homogeneous entity. This is a simple version of the homogeneous relationship.

A strict description is that the use of homogeneous relationships must meet the following two conditions:

    1. Homogeneous entities have the same members.
    2. If a homogeneous entity has method AI, each other homogeneous entity will have a method Bi corresponding to it, and:

A. If AI and AK are different, Bi and BK are different.

B AI and Bi can perform completely different operations.

Generally, developers can ignore this strict expression and use homogeneous relationships only with reference to definitions of simple versions. Shows the icon of the homogeneous relationship in the toolbar of the object graph:

III.Relational entity

The relational entity comes from the relationship between entities. Generally, a link is only a link, but sometimes it needs to be designed as an independent entity. Such an entity is called a relational entity. Currently, most modeling tools only support binary relational entities, that is, the relationships with two entities involved are designed as one entity. Emstudio supports the participation of any number of entities in relational entities, which fully reflects the provisions on Relational entities in the UML standard.

Open the project used in the previous chapter, or the reader creates a project by himself, creates a new entity graph under the project node, changes it to advanced, and then opens the entity graph. Select the link object button in the toolbar, as shown in:

Define a new relational entity in the object graph using the same method and rename it relationentity, as shown in:

First, it should be clear that the relational entity is also a simple entity, which can be seen from the generated source code. Because the parent class of a relational object is a simple object. It can be seen that a relational entity has one more roles than a simple object. This roles indicates all the entities involved in the current link, in the static model of emstudio, these involved entities are called roles ). Right-click the relationentity object and select role from the shortcut menu to open the role design page, as shown in:

The operations on this interface are basically the same as those on the previous Member design page. Click the Add button to define a new role, as shown in:

Select the entity attribute and select an object to indicate which object participates in the current link. The role name must be unique in the same relational entity. In addition, the only difference between roles is the role name rather than the entity type represented by the role. That is to say, the entities represented by different roles can be the same. After the source code is generated, the reader can see that the relationentity class has specific attributes to represent these roles. Emlib has a set of special operations that allow developers to control and use roles.

4.Composite entity

Composite entities are also a new entity type extended by the emstudio static model, which is not available in the UML standard. If a relational entity combines an entity at the independent entity level, the composite entity combines members of different entities. The same composite entity is also a simple entity, which can be verified from the generated source code. The following describes how to use composite entities. Select the combined object button in the toolbar, as shown in:

Then define a new composite entity in the object graph. It can be seen that the composite entity has one more elements group. In addition to defining members, a composite object can also use members of other entities as its own members. These entities that provide members to the composite entities are called elements, which are displayed in the elements group. Right-click the object, select the menu item property in the pop-up menu, open the object designer, rename the object to combentity, and then select the element page, as shown in:

The operations on this interface are basically the same as those on the previous Member design page. Click the Add button to define a new element, as shown in:

Select the entity attribute to set the object corresponding to the current element. Similar to a role in a relational object, an element name is unique in a composite object, rather than an element representing the object type. That is to say, different elements can correspond to entities of the same type. Select the mapped members attribute. On the member selection page, you can hook the members involved in the composite object, as shown in:

Click OK to return, close the Entity Designer, return to the main interface, save the project, and generate the code. You can see that the Code has relevant attributes to represent elements. From the source code perspective, the combined entity and the relational entity are very similar. Apart from the differences in the conceptual semantics of the static model, the two also have differences in the emlib ORM operations. When you use emlib to update an object, the relational object only updates the value of its members, and the value of its members is not updated. However, in addition to updating its own members, the composite entity also updates the element entity members. That is to say, the composite object can actually update the Member values of multiple entities at a time.

 

This section has all been described here, if you have any questions or need technical support to visit our website: http://www.WideUnion.com. We hope to hear your suggestions and requirements so that we can provide you with better products and services.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.