I have used this design pattern in several entity-component designs. Now I want to introduce it to my team:

It concerns a type-of relationship, where the instance structure and the type structure are mirrored using a naming convention:

Vehicle -- typeof -->  VehicleType

Vehicle and VehicleType can then be specialized (using composition or inheritance), but each side must mirror the other in class/table structure (not fields or methods):

PassengerCompartment    PassengerCompartmentType
 Passengers               NumberOfSeats 

CargoCompartment        CargoCompartmentType
 CargoWeight              CargoCapacity 

In this way, the programmer can deduce where relevant data is, without having to consult a diagram or documentation.

Does this pattern have a name?


I suppose it is a prototype pattern with additional restrictions based on typing https://www.oodesign.com/prototype-pattern.html. Always assume your specific design guidelines won't fit exactly* with common place design patterns , at the end of the day the implementation of a design pattern only makes sense around the specific problem you are going to solve with said pattern.

| improve this answer | |
  • 1
    Prototype seems more like cloning an existing instance. In my case I have a template (type) that the new instances are based on. – Rugbrød Jun 24 at 10:19
  • It's more like the Flyweight pattern. – Rugbrød Jun 24 at 10:20
  • The Flyweight patter is used to reuse/share objects where identity doesn't matter. The purpose is to limit the number of objects instantiated, and reuse where it makes sense. refactoring.guru/design-patterns/flyweight – quaabaam Jun 26 at 1:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.