Upload
rudolph-ross
View
223
Download
0
Tags:
Embed Size (px)
Citation preview
Training Course
Domain Modeling
2
What is the Domain model?
•An abstract data model•A reflection of reality•No ERD, closer to entity-oriented models•Consists of entities, attributes and associations
3
What is an entity?
•Something that exists in real life•“Blueprint for Mendix entities”
Examples:•Car•House•Client•Order•Product•Email message
4
How to add an entity?
•Click on the “Entity” button•Click on the desired location•Set the name of the entity in the “Properties” window
5
What is an attribute?
•“Provides information about an Entity”
•Client ← Name, Address, City•Car ← Brand, Type•Order ← OrderNumber, OrderDate
6
Attribute types
• AutoNumber (Automatically incrementing number)• Binary• Boolean (True or False)• Currency• DateTime• Enumeration (Collection of predefined values)• Float (Floating-point number: 1.12)• HashString• Integer (Small number)• Long (Big number) • String (Text)
7
How to add attributes to an entity?
•Double click on an entity•Go the ‘Attributes’ tab page•Click on the “Add” button•Enter the “Name”•Select “Type”
8
What are associations?
•“Indicates the relationship between entities”
•Car – Owner•Order – Client•Product – Product group•Book - Author
9
Association types
•Basic– Reference
•Advanced– Reference Set – 1-1 Reference (Reference BOTH)– MN Reference (Reference Set BOTH)
10
What is a reference?
•With a reference you can refer from one entity to another entity•In the given example the customer refers to country•The ‘1 to 0’ reference is the most common kind of association•Similar to ERD 1 – n relations
• Customer refers to 1 Country • Country can be referenced by multiple customers• The reference is stored in the Customer• The cardinality can be read as follows:
Customer refers to 1 country Country refers to 0 customers
11
Reference in XML
The reference is stored in the owner of the association which is indicated by the arrow (‘Order’ in the given example)
<Customer id="101"><Name>KLM</Name><Customer_Country>id_201</Customer_Country>
</Customer>
<Country id="201”><Name>Holland</Name>
</Country>
12
How to add a reference?
•Click on the “Add association” button•Click on the border of the meta entity (starting at the owner)•Keep the mouse button pressed•Drag the association to the border of the other entity
13
What is a reference set?
•With a reference set one entity refers to multiple other entities•In the example the Customer refers to many Groups•Similar to ERD ‘N – M relations’
• Customer refers to N groups• Group can be referenced by multiple customers• The relation is recorded in the customer• The cardinality can be read as follows:
Customer refers to N groups Group refers to 0 Customers
14
Reference set in XML
<Customer id="101"><Name>General Motors</Name><Customer_Group>id_201 id_202</Name>
</Customer>
<Group id="201”><Name>VIP</Name>
</Group>
<Group id="202”><Name>Christmas cards</Name>
</Group>
The reference is stored in the owner of the association which is indicated by the arrow (Customer in the given example)
15
How to add a reference set?
•Add an association•Click on the association•Set the property “Type” to “ReferenceSet”
16
What is a reference both?
•This indicates that two entities always belong together•Could also be modeled as one large entity•In the example the customer refers to a profile and profile to customer•Similar to ERD ‘1 – 1 relations’
• Customer refers to 1 profile• Profile then always refers to the same Customer• The relation is stored in both Customer and Profile• The cardinality can be read as follows:
Customer refers to 1 Profile Profile refers to 1 Customer
17
Reference both in XML
<Customer id="101"><Name>General Motors</Name><Customer_Profile>id_201</Customer_Profile>
</Customer>
<Group id="201”><Name>Profile_General Motors</Name>
<Customer_Profile>id_101</Customer_Profile></Group>
The reference is stored in the owner of the association which is indicated by the arrow (both Customer and Profile in the example)
18
How to add a reference both?
•Add an association•Click on the association•Set the property “Owner” to “Both”
19
What is a reference set both?
•With a reference set both, both entities refer to multiple other entities•In the given example, the Customer refers to many Groups and vice versa•Similar to ERD ‘N – M relations’•Hardly ever used
• Customer has maximum of N groups and vice versa• Group can belong to multiple customers and vice versa• The relation is stored in both Customer and Group• The cardinality can be read as follows:
Customer refers to N groups Group refers to N Customers
•If one entity is deleted, an associated entity is deleted as well•This is commonly used by – Reference both associations– When one entity in reality is modeled as two entities,
for example: Order & OrderLine
•Can be defined on both the parent or the child of the association•In the given example, the Profile will be deleted when the Customer is
deleted
20
What is cascading delete?
•Select the association•Click the ... Button in the “Delete behavior” in the explorer•Select the desired delete behavior (2nd radio button)
21
How do I configure cascading delete?
•This prevents an entity from being deleted if it is referenced by other entities
•This prevents the existence of orphans or invalid references in the database
•A message to the end user can be specified for each association•Always specify a message when blocking a delete•In the given example, a Country can’t be deleted if it is referenced by a
Customer
22
What is delete prevention?
•Select the association•Click the ... Button in the “Delete behavior” in the explorer•Select the desired delete behavior and enter a message for the end
user
23
How do I configure delete prevention?
24
Combining cascading delete & delete prevention
Question:
What happens if a continent is deleted that contains countries with customers?
Countries can only be deleted if they are not referenced by any customer
If a continent is deleted all countries are deleted as well
•Before an entity is committed all validations rules are checked•Validation rules apply to attributes•If one rule is violated then the commit action will be cancelled•For each rule you can specify an error message •All messages are returned to the caller •If the caller is the client portal, the messages will be shown in the data
view•Validation rules are visualized in the model (green check next to attribute)
25
What are validation rules?
•There are different kinds of validation rules:– Required The attribute is required to have a value– Unique The values of this attribute is unique across all instances of
an entity– Equals The value equals a predefined value or other attribute– Range The value lies between two other values
(other attributes or fixed values)– Regular expression The value conforms to a regular expression– Maximum length There is a maximum length for the attribute
26
What are validation rules?
•Double click on the entity•Open tab page “Validation rules”•Click the “Add” button
27
How to configure validation rules?
•Select the attribute•Define an error message, that is shown when the rule is violated•Select the type of validation rule•Set the necessary values•Click OK
28
How to configure validation rules?
•A term ‘borrowed’ from Entity-Oriented programming•A subentity inherits from a superentity.•The subentity inherits all attributes including validation rules
and associations of the superentity. •The superentity is extended, also called specialization•In the example both Customer and Employee are
specializations from User
29
What is Generalization?
•Customer has the attributes: – Address– Name– Password
•Employee has the attributes:– Function– Name– Password
30
What is Generalization?
•Select the entity in the Domain model•Click on the … button of the property “Generalization”•Select the superentity in the explorer popup•Click Select
31
How do I configure inheritance?
•When entities have a number of common attributes (keeps the model clear)•When entities can be generalized as a super entity•When you want to use functionality from another module (e.g. the System model)•When two entities need to be displayed in one list (only shows the common attributes)
32
When to use Generalization?
•Performance reduction through complex joins on database•Challenging when used in combination with complex business logic
and validation rules•It becomes difficult to oversee implications of changes to the
domain model when a lot of generalization is used
33
Generalization Drawbacks