Advanced ER: Enhanced ER (EER) Advanced ER: Enhanced ER (EER)

Extending the ER model with Object-Oriented concepts: Subclasses, Superclasses, Inheritance, and Specialization. توسيع نموذج ER بمفاهيم كائنية التوجه (Object-Oriented): Subclasses, Superclasses, Inheritance, و Specialization.

Ternary Relationships Ternary Relationships Subclass/Superclass Subclass/Superclass Inheritance Inheritance Specialization Specialization Generalization Generalization

Higher-Degree Relationships Higher-Degree Relationships (علاقات متعددة الدرجات)

While binary relationships (degree 2) are most common, some situations require degree > 2. بينما العلاقات الثنائية (degree 2) هي الأكثر شيوعاً، تتطلب بعض الحالات degree > 2.

Ternary Relationship (Degree 3) Ternary Relationship (علاقة ثلاثية)

Example: SUPPLY relates Supplier, Part, and Project simultaneously. مثال: SUPPLY تربط Supplier, Part, و Project في آن واحد.

  • Cannot be easily decomposed into 3 binary relationships without losing semantics. لا يمكن تفكيكها بسهولة إلى 3 علاقات ثنائية دون فقدان المعنى (Semantics).
  • Attributes (e.g., Quantity) belong to the combination of all three. السمات (مثل: الكمية) تنتمي إلى المزيج المكون من الثلاثة.
Aggregation Aggregation

An abstraction concept for building composite objects. Used when a relationship itself needs to participate in another relationship. مفهوم تجريدي لبناء كائنات مركبة. يُستخدم عندما تحتاج العلاقة نفسها للمشاركة في علاقة أخرى.

Subclasses & Superclasses Subclasses & Superclasses

The Concept المفهوم

An entity type may have meaningful subgroupings.
Example: EMPLOYEE may be subdivided into SECRETARY, ENGINEER, TECHNICIAN.
قد يكون لنوع الكيان مجموعات فرعية ذات معنى.
مثال: EMPLOYEE يمكن تقسيمه إلى SECRETARY, ENGINEER, TECHNICIAN.

  • Superclass:Superclass: The generic entity (EMPLOYEE). الكيان العام (EMPLOYEE).
  • Subclass:Subclass: The specific subgroup (ENGINEER). المجموعة الفرعية المحددة (ENGINEER).
  • Relationship:Relationship: IS-A (e.g., ENGINEER IS-A EMPLOYEE). IS-A (مثال: المهندس هو موظف).

Attribute Inheritance Attribute Inheritance (وراثة السمات)

An entity in the Subclass inherits: يرث الكيان في الـ Subclass:

  1. All Attributes of the Superclass. جميع Attributes الخاصة بالـ Superclass.
  2. All Relationships the Superclass participates in. جميع Relationships التي يشارك فيها الـ Superclass.
Local Attributes: Attributes specific to the subclass (e.g., `TypingSpeed` for SECRETARY). Local Attributes: سمات خاصة بالـ subclass (مثال: `TypingSpeed` للسكرتير).

Specialization vs Generalization Specialization vs Generalization

Specialization Specialization

Top-Down Process عملية من أعلى لأسفل

Start with a single entity (EMPLOYEE) and define subclasses (SECRETARY, ENGINEER) based on distinguishing characteristics. تبدأ بكيان واحد (EMPLOYEE) وتحدد subclasses (SECRETARY, ENGINEER) بناءً على خصائص مميزة.

Generalization Generalization

Bottom-Up Process عملية من أسفل لأعلى

Start with separate entities (CAR, TRUCK) and generalize them into a single superclass (VEHICLE) based on common features. تبدأ بكيانات منفصلة (CAR, TRUCK) وتعممها في superclass واحد (VEHICLE) بناءً على الميزات المشتركة.

EER Diagram: Employee Hierarchy EER Diagram: Employee Hierarchy

classDiagram EMPLOYEE <|-- SECRETARY EMPLOYEE <|-- ENGINEER EMPLOYEE <|-- TECHNICIAN class EMPLOYEE { Name SSN Salary } class SECRETARY { TypingSpeed } class ENGINEER { EngType } class TECHNICIAN { TGrade }

Notation: The arrow points to the Superclass (Inheritance). الترميز: السهم يشير إلى الـ Superclass (Inheritance).

Constraints Constraints (القيود)

1. Disjointness Constraint 1. Disjointness Constraint

Can an entity be a member of more than one subclass? هل يمكن للكيان أن يكون عضواً في أكثر من subclass؟

  • d Disjoint:Disjoint: NO overlap. (Entity must be either A or B, not both). لا يوجد تداخل. (الكيان يجب أن يكون إما A أو B، وليس كلاهما).
  • o Overlapping:Overlapping: Overlap allowed. (Entity can be both A and B). التداخل مسموح. (يمكن للكيان أن يكون A و B معاً).

2. Completeness Constraint 2. Completeness Constraint

Must every entity in the superclass be a member of some subclass? هل يجب أن يكون كل كيان في الـ superclass عضواً في subclass ما؟

  • Total YES. (Double Line). Every Employee MUST be a Sec, Eng, or Tech. نعم. (خط مزدوج). كل موظف يجب أن يكون Sec, Eng, أو Tech.
  • Partial NO. (Single Line). An Employee can exist without being any of the subclasses. لا. (خط مفرد). يمكن للموظف أن يوجد دون أن يكون في أي من الـ subclasses.

The Exam Vault خزنة الاختبار

Professor's Secrets & Trap Avoidance أسرار البروفيسور وتجنب الفخاخ

TRAP: Disjoint vs Overlapping فخ: Disjoint vs Overlapping

Disjoint (d): E.g., Employee is either Salaried OR Hourly. Cannot be both.
Overlapping (o): E.g., Person can be Employee AND Student. Look for the little 'd' or 'o' inside the circle in EER diagrams.
Disjoint (d): مثال: الموظف إما Salaried أو Hourly. لا يمكن أن يكون الاثنين.
Overlapping (o): مثال: الشخص يمكن أن يكون Employee و Student. ابحث عن حرف 'd' أو 'o' الصغير داخل الدائرة في مخططات EER.

TRAP: Inheritance Direction فخ: اتجاه الـ Inheritance

Attributes flow DOWN. Subclasses inherit from Superclass. Subclasses NEVER pass their specific attributes UP to the Superclass. السمات تتدفق لأسفل (DOWN). الـ Subclasses ترث من الـ Superclass. الـ Subclasses لا تمرر سماتها الخاصة للأعلى إلى الـ Superclass أبداً.

SECRET: Union Type سر: Union Type

A subclass with multiple superclasses is a Shared Subclass (Multiple Inheritance). If the superclasses are different entity types (e.g., Car and Truck owning a "RegisteredVehicle" license), it's called a Category (Union Type). الـ subclass الذي له multiple superclasses هو Shared Subclass (Multiple Inheritance). إذا كانت الـ superclasses من أنواع كيانات مختلفة (مثل Car و Truck يمتلكان رخصة "RegisteredVehicle")، يسمى هذا Category (Union Type).

KEY CONCEPT: When to Specialize? مفهوم أساسي: متى نستخدم Specialization؟

Create a subclass only if:
1. The subclass has unique attributes not shared by others.
2. The subclass participates in a unique relationship.
قم بإنشاء subclass فقط إذا:
1. كان للـ subclass سمات فريدة (unique attributes) لا يشاركه فيها الآخرون.
2. كان الـ subclass يشارك في علاقة فريدة (unique relationship).