33
Training Course Domain Modeling

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

Embed Size (px)

Citation preview

Page 1: 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

Training Course

Domain Modeling

Frans Verschoor
Page 2: 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

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

Frans Verschoor
Page 3: 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

3

What is an entity?

•Something that exists in real life•“Blueprint for Mendix entities”

Examples:•Car•House•Client•Order•Product•Email message

Frans Verschoor
Page 4: 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

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

Frans Verschoor
Changed
Frans Verschoor
Frans Verschoor
Page 5: 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

5

What is an attribute?

•“Provides information about an Entity”

•Client ← Name, Address, City•Car ← Brand, Type•Order ← OrderNumber, OrderDate

Page 6: 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

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)

Frans Verschoor
Frans Verschoor
Frans Verschoor
Page 7: 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

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”

Page 8: 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

8

What are associations?

•“Indicates the relationship between entities”

•Car – Owner•Order – Client•Product – Product group•Book - Author

Page 9: 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

9

Association types

•Basic– Reference

•Advanced– Reference Set – 1-1 Reference (Reference BOTH)– MN Reference (Reference Set BOTH)

Frans Verschoor
Frans Verschoor
Frans Verschoor
Frans Verschoor
Page 10: 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

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

Frans Verschoor
Frans Verschoor
Page 11: 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

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>

Frans Verschoor
Is deze slide relevant?
Page 12: 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

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

Frans Verschoor
Is het nodig om het toevoegen vanuit een entity te beschrijven?
Page 13: 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

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

Frans Verschoor
Frans Verschoor
Page 14: 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

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)

Frans Verschoor
Nodig?
Page 15: 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

15

How to add a reference set?

•Add an association•Click on the association•Set the property “Type” to “ReferenceSet”

Frans Verschoor
Vervangen?
Page 16: 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

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

Frans Verschoor
Frans Verschoor
Frans Verschoor
Page 17: 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

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)

Frans Verschoor
Nodig?
Page 18: 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

18

How to add a reference both?

•Add an association•Click on the association•Set the property “Owner” to “Both”

Frans Verschoor
Vervangen?
Page 19: 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

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

Frans Verschoor
Frans Verschoor
Frans Verschoor
Frans Verschoor
Frans Verschoor
Page 20: 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

•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?

Frans Verschoor
Frans Verschoor
Page 21: 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

•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?

Frans Verschoor
Vervangen?
Page 22: 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

•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?

Page 23: 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

•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?

Frans Verschoor
Page 24: 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

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

Page 25: 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

•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?

Page 26: 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

•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?

Frans Verschoor
Frans Verschoor
Page 27: 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

•Double click on the entity•Open tab page “Validation rules”•Click the “Add” button

27

How to configure validation rules?

Frans Verschoor
Vervangen?
Page 28: 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

•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?

Page 29: 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

•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?

Frans Verschoor
Klopt dat nog?
Frans Verschoor
Stond sub. Dat is niet correct toch?
Frans Verschoor
Page 30: 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

•Customer has the attributes: – Address– Name– Password

•Employee has the attributes:– Function– Name– Password

30

What is Generalization?

Page 31: 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

•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?

Frans Verschoor
Moet domain model worden
Frans Verschoor
Page 32: 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

•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?

Frans Verschoor
Vind ik niet de eerste reden
Frans Verschoor
Niet duidelijk
Frans Verschoor
Dus wanneer ze op bepaald niveau dezelfde entiteit zijn...
Page 33: 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

•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

Frans Verschoor
Frans Verschoor