Sub topic 4
Specialization, Generalization, and Aggregation
Assume you know entities, attributes, relationships, cardinality, and participation constraints. This chapter uses those ideas to extend an entity-relationship (ER) model when some entities share properties or when a relationship must participate in another relationship.
Specialization
Specialization is a top-down process. Start with one general entity set and divide it into more specific entity sets called subclasses. The original entity set is the superclass.
For example, Employee can be specialized into Manager and Developer. Every manager and developer is an employee, so each subclass inherits the superclass's attributes, such as emp_id and name. A subclass can also have its own attributes, such as bonus for managers or programming_language for developers.
Two constraints describe how subclasses relate to their superclass:
| Constraint | Meaning |
|---|---|
| Disjoint | An entity can belong to at most one subclass |
| Overlapping | An entity can belong to more than one subclass |
| Total | Every superclass entity must belong to a subclass |
| Partial | Some superclass entities may belong to no subclass |
These constraints are independent. A specialization may be total and disjoint, partial and disjoint, total and overlapping, or partial and overlapping.
Generalization
Generalization is the reverse, bottom-up process. Combine several entity sets with common attributes into a superclass. For example, Car and Truck can be generalized into Vehicle. The common attributes move to Vehicle, while subclass-specific attributes remain in Car or Truck.
Specialization emphasizes differences. Generalization emphasizes shared structure. Both produce the same extended ER concept: a superclass with subclasses and an inheritance relationship.
Aggregation
Aggregation treats a relationship set and its participating entities as one higher-level object. This is useful when a relationship itself must participate in another relationship.
Suppose an Employee works on a Project, and a Manager monitors that work assignment. The works_on relationship connects Employee and Project. With aggregation, the entire works_on instance can participate in the monitors relationship with Manager.
Aggregation does not mean grouping rows for a report. It is an ER modelling mechanism for expressing a relationship involving another relationship.
Relational Mapping
A common relational mapping creates one table for the superclass and one table for each subclass. The subclass table uses the same primary key as the superclass and also makes that key a foreign key.
For Employee, Manager, and Developer:
Employee(emp_id, name)Manager(emp_id, bonus)Developer(emp_id, programming_language)
A total, disjoint specialization may instead use one table with a type column. That design is simpler for some queries but can create many null values when subclasses have different attributes.
Exercise
An employee may be both a researcher and a manager, but every employee must be at least one of these. What constraints describe this specialization?
Show answer
It is overlapping because membership in both subclasses is allowed, and total because every employee must belong to at least one subclass.