Adobe Systems 1 Data Modeling, Entity-Relationship Diagram PB007 Software Engineering I Lukáš Daubner daubner@mail.muni.cz A picture containing text Description automatically generated PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram Adobe Systems PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram 2 Entity-Relationship Diagram ̶Data model ̶ ̶Not a part of UML ̶Representing the logical structure of relational database ̶ ̶Its main components are: ̶Entities ̶Relations ̶Attributes Adobe Systems PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram 3 Entity-Relationship Diagram Graphical user interface Description automatically generated Adobe Systems PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram 4 Two Worlds Collide A picture containing building, street, dark, sitting Description automatically generated Adobe Systems PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram 5 Two Worlds Collide ̶World of Objects – Class Diagram ̶Captures data and operations ̶Classes are connected with different relationships with different semantics ̶Objects have own dynamic lifecycle ̶Manipulation with data through object interaction ̶ ̶World of Data – Entity-Relationship Diagram ̶Captures just data ̶Simple relationships ̶Represents tables in relational database ̶Manipulation with data through relational algebra ̶ ̶ Adobe Systems PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram 6 Object-Relational Mapping ̶Conversion „between the worlds“ ̶Persistent class ~ Entity type (table) ̶Object ~ Entity (table row) ̶Class attribute ~ Entity attribute (table column) ̶Association/Aggregation/Composition ~ Relation (connection via foreign keys) ̶Inheritance ~ … (manual work needed, see following slides) ̶ ̶Mapping is not always 1:1! ̶Single class can be mapped to multiple tables ̶And vice versa ̶Not all classes are persistent (objects stored in database) ̶ Adobe Systems PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram 7 Example Object-Relational Mapping Graphical user interface, text, application Description automatically generated Adobe Systems PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram 8 Object-Relational Mapping – Inheritance ̶Each class becomes a table ̶Type attribute differentiates the subclass type ̶One object instance in multiple tables ̶More difficult data access 1:1 Mapping Graphical user interface, application Description automatically generated Adobe Systems PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram 9 Object-Relational Mapping – Inheritance ̶All attributes in one table ̶Some will have NULL value ̶Breaks the 4.NF ̶Suitable for small number of subclasses and few attributes ̶ Merge to superclass Adobe Systems PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram 10 Object-Relational Mapping – Inheritance ̶Superclass attributes are copied to non-abstract subclass tables ̶Suitable if: ̶Superclass has few attributes ̶Many subclasses ̶Subclasses have many attributes ̶ Propagation to subclasses Adobe Systems PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram 11 Normal Forms ̶Technique for data organization and good database design ̶ ̶Elimination of repetitive data ̶ ̶Reduction of table complexity ̶ ̶Problem prevention ̶E.g., update anomalies Adobe Systems PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram 12 1. Normal Form Normal Forms ̶Satisfies 0. NF (yes, it actually exists) ̶Each attribute is atomic Adobe Systems PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram 13 2. Normal Form Normal Forms ̶Satisfies 1. NF ̶ ̶No partial dependency ̶Each non-key attribute are fully dependent on candidate keys Adobe Systems PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram 14 3. Normal Form Normal Forms ̶Satisfies 2. NF ̶ ̶No transitive dependency ̶Each non-key attribute is dependent on primary key (and candidate keys) only ̶Non-key attributes are mutually independent Adobe Systems PB007 Software Engineering I — Data Modeling, Entity-Relationship Diagram 15 You gotta do what you gotta do Task for this week ̶Process the feedback ̶ ̶Create ERD based on the class diagram ̶Keep it consistent – you model the same system ̶Decompose M:N relationships using entities ̶Normalize to 3. NF ̶ ̶Based on the EDR create separate example violating 3. and 2. NF ̶Example – don‘t need to create whole new diagram ̶Add notes explaining the NF violations