Thanks for your reply!
Holy Joe wrote:
Are there two different sets of tags for each client class (e.g., Document): The set of tags allowed for documents, and then the set of actual tags applied to each document?
That is indeed one way of looking at it. But the tags need not be a "set of allowed tags" but that's not important I guess. What I mean is that the user can add new tags themselves and/or they might be preexisting tags. That is just an implementation detail though.
Use case scenario:
A user uploads a document. When uploading and/or afterwards the user can add different tags/labels/categories, whatever one would like to call them). For example adding the tags "car" and "racing" to that particular document.
Use case scenario 2:
A user wants to see all documents that have a tag/label/category "car".
The same thing happens if he uploads something else, a picture, a file etc etc.
But the different tag sets are separate for different objects (documents and pictures don't share the same tag sets for example) . I was thinking that it might be possible to have a reusabale set of classes and interfaces by using generics.
Reusable in the programming sense, for multiple different projects for example, but also in a given project of course.
Let's say I one day create a web site hosting documents that can be tagged/labeled in the above way. The other day it's the same thing but I'm creating a totally different web site that has a picture upload capability where the users can label/tag the pictures with "humor", "car" etc. Or it might be an added requirement one day to have one of these sites also able to tag the users in the same way but the only relation it has to the previous tag-capability is the pattern. Completely different set of user and/or pre-defined tags.
Maybe it's just quicker to just make them separate for each project and/or object and from scratch. But I was thinking it was a nice idea to basically just add a "Taggable interface" or similar to the obejct that I would like to be able to assign zero or more tags/labels/categories to. Then also notify hibernate of a Tag<Document> subclass, bascially empty. Using generics it seems possible to do and hibernate allows me along way to do it, but I can't get the perfect solution 100% visualized for myself.. yet :) The empty Tag<Document> class extending/implementing Tag<?> for example, is it really necessary? I guess so.
My solution/tries so far got me this:
A Taggable<?> that the object that needs this capabilty has to implement with a specific instance, itself. So a Document class that would like to be able to get Tagged:
Code:
class Document implements Taggable<Document> {
...
}
class DocumentTag extends AbstractTag<Document> {
}
interface Tag<T> {
...
}
class AbstractTag<T> implements Tag<T> {
...
}
And the Taggable and Tag interfaces force them to implement the manytomany relationships get & set methods along with the annotation.
I think there is a mixin or something in Ruby on Rails or a plugin to RoR that does this and it would be nice to be able to do the same.
I would appreciate suggestions/feedback/comments/pointers etc!