views:

52

answers:

1

Hi all, i have a parent entity Service and a child ExtendedService in a SINGLE_TABLE inheritance.

A third entity ServiceCollector need to include both entites Service and ExtendedService. This is a fixed requirement, and with this design i can realize it using polymorphism.

THE PROBLEM: Very often i need to retrieve ONLY the parent class Service, so i query it by discriminator column... i think this is a bad design for my purpouse, isn't true?

This is a simple example, indeed i have a lot of Service subclasses, think for example to a shop that sell different product, each product can have a different properties.

Thanks in advance.

+1  A: 

If every ExtendedService isn't valid as a response to a query for Service, sounds more like you have Templating through Inheritance, rather than Polymorphism. A simple fix is to make Service abstract, so you have AbstractService and an empty class Service that extends it and just defines the DiscriminatorValue. (Then ExtendedService extends AbstractService, etc.)

Mapping the discriminator column to query it isn't exactly the end of the world, if everything else is working fine for you. Personally I'd file it more towards "Inelegant" than "Bad Design" but that's just opinion.

Affe
So, have a empty entity(Service) that inherit from an abstract entity, is a better choice?
blow
In this one man's opinion it more accurately models your domain objects, based on the extremely limited knowledge we have about them from your post. I won't be so bold as to declare it universally 'better'. ;) There are ups and downs to both. This way should eliminate the need to 'cheat' discriminator columns, which you indicated was a goal.
Affe