Search⌘ K

Class Hierarchy Merge

Explore the Class Hierarchy Merge design pattern to simplify object-oriented class structures by combining subclass properties into an expanded root class. Understand how to implement category attributes with enumeration types and optional properties, ensuring data consistency through invariant constraints. This lesson helps you refactor disjoint subclass models effectively.

We'll cover the following...

The Class Hierarchy Merge design pattern

Consider the simple class hierarchy of the design model in the subtypessubtypes figure, which shows a disjoint segmentation of the class Book. Whenever there’s only one level (or a few levels) of subtyping, and each subtype has only one (or a few) additional properties, we can refactor the class hierarchy. This can be done if we merge all the additional properties of all subclasses into an expanded version of the root class so that these subclasses can be dropped from the model. This will lead to a simplified model.

This Class Hierarchy Merge design pattern comes in two forms. In its simplest form, the segmentations of the ...