1 Reply Latest reply on Sep 30, 2009 5:06 PM by B Tomic

    Does multipurpose EntityHome make sense?

    B Tomic Newbie

      I have a strange requirement, and with it comes a strange problem.

      My entities (like Book, Movie etc) are all subclasses of Item, are all mapped to the same table and, apart from the discriminator column value, they have no distinguishing characteristics of their own.

      So Item table could look like this:

       Id   |  Name    | Type (discriminator)
       1    |  book 1  | book
       2    |  movie 1 | movie

      On the home pages, there is a dropdown list with all available categories (books, movies etc.), and a user can perform CRUD operations on entities of that type. The problem with this is that if I had a separate Home for every type (i.e. BookHome, MovieHome etc.) I would need a very complicated scheme for checking what component to instantiate and refer to throughout the application. Instead, it would be great if I could somehow create a mutual ItemHome that could be used for managing an instance of any of the subclasses.

      Is this possible? Does it make sense? Am I better off creating a separate subset of CRUD components (Homes, Lists etc.) and pages (bookList, bookEdit, movieList etc) for every one of about 10 types (although I would avoid this if at all possible)? What are your thoughts on this?
      I am completely lost, so any advice at all would be of great help.

        • 1. Re: Does multipurpose EntityHome make sense?
          B Tomic Newbie

          Hmmm... Seems I was over thinking this.
          Can I simply add a property that holds type to Home and override getInstance() so that it creates the class of that type through reflection?

          Something like this:

          getInstance() {
            ... //do all checks and whatever else this method usually does

          Is this approach... sane?

          Any insight would be appreciated.