What is the correct pattern to use in this case?

Posted by nulliusinverba on Programmers See other posts from Programmers or by nulliusinverba
Published on 2012-10-13T10:28:29Z Indexed on 2012/10/13 15:53 UTC
Read the original article Hit count: 131

Filed under:

I'm sure this scenario has arisen before, and I want to know what experience has taught to be the best solution.

I have a number of classes that are all of a kind. Say all the objects are "Content". They may be "Article", or "Book" for example.

The reason I want the "Content" abstraction is because I want to define a number of behaviours for all "Content" objects and not have to build a new DB Table and 10 classes of essentially the same code for each type of "Content". For example, to attach a "Tag" or a "Premise" to a content object would be much nicer if, say, I just had two columns one for ContentID and one for TagID.

A solution I've played around with is to have a Content table with a unique ID, and then to have foreign key references on all the other tables (Book, Article, etc). This has actually proven quite solid, but I'm just not sure about it.

Do you know how to call this described pattern?

© Programmers or respective owner

Related posts about design-patterns