1 2 Previous Next 17 Replies Latest reply: Jul 15, 2010 1:48 AM by 843853 RSS

    editorial content website - design questions

    843853
      Hello everyone,

      I am developing an editorial content website with some community functionalities. Currently i am working on the design part, API design and so on, but i am at an stage where i am not sure if i am following the right way.

      I am using lots of interfaces, i have a "huge" main Content interface that defines a lot of common behaviour like:
      getHeadLine()
      getSummary()
      getComments()
      getAuthor()
      getKeywords()
      and so on....

      Then i have some content type interfaces extending Content like, Article, Gallery, Event, Comment, etc. I also have implementation classes for the content type interfaces (ArticleImpl, GalleryImpl, EventImpl, CommentImpl, etc).

      I finnaly have defined common behaviour for all the content types as interfaces: Commentable, Rateable, Viewable and so on.

      I would like to ask you experts if i am on the right track, because i dont want to fail at design stage.

      Thanks a lot in advance
        • 1. Re: editorial content website - design questions
          dcminter
          My advice (seriously) is to stop building a CMS and go and find an existing CMS (commercial or free) to use instead.
          • 2. Re: editorial content website - design questions
            843853
            Hello dcminter,

            Thanks for the response, but i am not allowed to use an existing CMS (Company requirement), i have to develop the website, cms and web from a scratch. That is why i asked for advice.

            Thanks again
            • 3. Re: editorial content website - design questions
              800387
              My guess is you will eventually have the bad design smell of [parallel inheritance hierarchies|http://sourcemaking.com/refactoring/parallel-inheritance-hierarchies] if you go down that route. Are all of those really inheritance? My guess is you can get away with composition and delegation rather than inheritance for most of those types (interfaces and classes).

              - Saish
              • 4. Re: editorial content website - design questions
                843853
                Thanks a lot Saish,

                I get the point with composition but i am not sure if i understand delegation pattern. Do you mean to get the rid of the main Content interface and have just a few classes (Article, Product, Event, etc)?

                What about the "behaviours"? should i keep my Rateable, Commentable, Viewable interfaces and have my Article, Product...classes implement them?

                Thanks a lot for the help
                • 5. Re: editorial content website - design questions
                  800387
                  I like the idea of lower-level interfaces such as Commentable, Rateable, etc. that are mixed and matched to create higher level interfaces such as Content. My concern was extending Content with interfaces, and then having implementations for each. You have a parallel hierarchy. I could see something like
                  interface Content extends Commentable, Rateable, Viewable {}
                  
                  interface Article extends Content, Authored {}
                  
                  interface Gallery extends Content, Paged {}
                  
                  interface Event extends Content, Subscribable {}
                  Your service classes could do something like the following:
                  interface ViewingService {
                    public abstract void view(final Viewable target);
                  
                    public abstract void rate(final Rateable target, final Rating rating);
                  }
                  - Saish

                  • 6. Re: editorial content website - design questions
                    843853
                    Hello Saish, you are really helpful :)

                    Ok, i see your point and i like the approach but, isn´t it more or less my first idea? i mean, we have
                    interface Content extends Commentable, Rateable, Viewable {}
                     
                    interface Article extends Content, Authored {}
                     
                    interface Gallery extends Content, Paged {}
                     
                    interface Event extends Content, Subscribable {}
                    And finally you need implementation classes for those interfaces, right? pretty much the same that i had at the start...maybe am i missing something?

                    Thanks a lot again!
                    • 7. Re: editorial content website - design questions
                      800387
                      Personally, I would not make the Content interface, I would simply use the lower level ones in combinations with various implementations (or make Content into AbstractContent as an abstract class with common behavior). However, I wanted to include that as an homage to your original design.

                      - Saish
                      • 8. Re: editorial content website - design questions
                        843853
                        Then, for example, you mean to have an ArticleImpl class that implements Article interface, which extends from Authored and Commentable, right? Do you consider that a good design? to me sounds good, but i don´t want to fail at this stage.

                        Your help is very much appreciate
                        • 9. Re: editorial content website - design questions
                          800387
                          You should not worry so much about your implementation classes. If you code to interfaces, which should be your goal, that gives you the freedom to change your implementations without affecting other portions of code. What you said sounds fine to me.

                          - Saish
                          • 10. Re: editorial content website - design questions
                            843853
                            Thank you very much, i feel more comfortable now.
                            • 11. Re: editorial content website - design questions
                              800387
                              Best of luck.

                              - Saish
                              • 12. Re: editorial content website - design questions
                                843853
                                I think Saish's idea is cool, although you may want to add a few more methods per interface.

                                On the subject of delegation, you will will need to do this if you don't want to implement each part of your inherited interfaces over and over again for each concrete derived class - particularly if any of the interfaces have significant implementations.

                                So for example you may want a class CommentableAuthorableItem which is an implementation of both Commentable and Authorable.

                                Rather than..
                                class CommentableAuthorableItem implements Commentable, Authorable
                                {
                                  private List<Comment>  comments;
                                  private String author;
                                
                                 public List<Comment> getComments()
                                 {
                                     return comments;
                                 }
                                
                                 public String getAuthor()
                                 {
                                    return author;
                                 }
                                
                                }
                                have
                                class AuthorableImpl implements Authorable
                                {
                                    private String author;
                                
                                    public String getAuthor()
                                    {
                                       return author;
                                    }
                                }
                                
                                class Commentable implementa Commentable
                                {
                                    private List<Comment> comments;
                                
                                   public List<Comment> getComments()
                                   {
                                         return comments;
                                   }
                                }
                                and then have
                                class CommentableAuthorableItem implements Commentable, Authorable
                                {
                                  private Commentable  commentable = new CommentableImpl();
                                  private Authorable authorable = new AuthorableImpl();     
                                
                                 public List<Comment> getComments()
                                 {
                                     return commentable.getComments();
                                 }
                                
                                 public String getAuthor()
                                 {
                                    return authorable.getAuthor();
                                 }
                                
                                }
                                This is what is meant by delegation and follows the golden rule of 'favoring composition over inheritance'.
                                • 13. Re: editorial content website - design questions
                                  843853
                                  Thanks Paratheosis, great help there :). Got to love these forums
                                  • 14. Re: editorial content website - design questions
                                    843853
                                    Another Question Saish, if you don´t mind. I am not sure if i get the idea of:
                                    interface ViewingService {
                                      public abstract void view(final Viewable target);
                                     
                                      public abstract void rate(final Rateable target, final Rating rating);
                                    }
                                    how do you use it? what is exactly the point on using it?

                                    Thank you
                                    1 2 Previous Next