AlgoPlusAlgoPlus
Learn/Databases
Lesson

Generalization & Aggregation

Two extended-ER tools: pull shared features into a superclass (ISA), and treat a whole relationship as one abstract entity.

8 min read Watch it move Build it

Plain entities and relationships can't capture every structure. The extended ER model adds two tools. Generalization pulls the features many entity types share up into one general superclass; its subclasses inherit those features and add their own, joined by an ISA ('is a') link. Aggregation treats an entire relationship — together with the entities it connects — as a single higher-level entity, so another relationship can attach to it.

Generalization vs specialization — same picture, two directions

  1. 1Generalization is *bottom-up*: you notice Student and Employee both have name and address, so you gather those shared features into a superclass Person.
  2. 2Specialization is *top-down*: you start with Person and split it into more specific sub-types Student and Employee.
  3. 3Either way the result is the same ISA hierarchy, and inheritance means each subclass automatically has all of the superclass's attributes without restating them.
A concrete hierarchy
Person (superclass) holds person_id, name. Student ISA Person and adds gpa. Employee ISA Person and adds salary. A Student *is a* Person, so it has name for free and never redeclares it.

Turning an ISA hierarchy into tables

One common mapping keeps the superclass as its own table and gives each subclass a table whose primary key is *also* a foreign key back to the superclass — so the subclass row and its parent row share the same identifier.

CREATE TABLE Person (
  person_id INT PRIMARY KEY,
  name      VARCHAR(60)
);
CREATE TABLE Student (
  person_id INT PRIMARY KEY REFERENCES Person(person_id), -- key AND foreign key
  gpa       DECIMAL(3,2)
);
CREATE TABLE Employee (
  person_id INT PRIMARY KEY REFERENCES Person(person_id),
  salary    INT
);

Aggregation — a relationship as an entity

Suppose Employee works-on Project (a relationship). Now you want to record that a Manager monitors that whole working-on arrangement — not just an employee, and not just a project, but the *pairing*. Aggregation lets you box the works-on relationship into a single abstract entity that the monitors relationship can point at.

Aggregation vs a normal relationship
You reach for aggregation only when you need a relationship of a relationship — a link whose participant is itself a relationship-plus-its-entities. If you just need entities linked, an ordinary diamond is enough.
Check yourself
What does the ISA link between Student and Person let Student avoid?