Vidya
Vidya

Reputation: 8197

OO design question

How do I Design an OO discussion forum. What classes and functions will it have. Thanks!

  Class User 
    {
     $name;
     $useid;
    $fname;
    $lname;
    Topic createTopic() ;
    postMessage(Topic topic_id);
    login ($userid)
    logout($userid)

    }

    Class Adminuser extends User
    {
       CreateForum()
    }

    Class Normaluser extends User
    {

    }

    Class Forum
    {
     Topic[]  topic_objs;
    $forum_id;
    $forum_name;
    $forum_desc;
    getAllTopics();
    }


    Class Topic
    {
    $topic_id;
    $topic_name;
    $topic_desc
    Replies[] reply_objs ;
    getAllMessages() ;

    }

    Class Replies
    {
       Topic topic_obj;
       $content ;
      }
    Class Site 
   {
     Users[] users_obj;
     Forum[] forums_obj;
   getUsersList();
   getForumsList();

   }

Can anyone suggest some ideas so that I can improve and complete the design .

Upvotes: 0

Views: 167

Answers (3)

The Archetypal Paul
The Archetypal Paul

Reputation: 41749

Let's start with a scenario.

Forum user Joe looks at the site

Joe enters the URL for the forum on his browser.

Joe logs into the forum. He selects the option to be logged in automatically next time

Joe sees a list of his forums, grouped into categories, with titles and a short description.

Other forums exist, but he cannot see those.

Forums containing new topics, or new replies to topics since Joe last viewed the forum are highlighted.

Joe views one of the forums with activity since he last visited. He sees a list of topics, in order of last activity (either creation date of new topic or date of last reply).

Topics changed since Joe last viewed them are highlighted.

Joe looks at a few topics that have changed since his last visit. The topic and any replies are listed in order of creation (not modification - topics and replies can be edited, but that doesn't change the order)

Topics have a subject line, tags, an author name, a date of creation and of last edit, and a body. Joe is shown all these, except the last edit date is shown only if it is different from the creation date. Replies have just an author name, a creation date and a last edit date. Again, the last edit date is shown only if it is not the same as the creation date.

Joe revisits the list of articles for the forum. This time, the articles he has now viewed are no longer highlighted, but other articles changed since his lat visit that he has not yet read are.

Joe revisits an article, and makes a reply to one of the other replies. The body of that reply is included, quoted, with author attribution,in the editor window for his reply. He deletes some of the body and adds his own response. He selects "Send" and is returned to the topic.

He is warned that another reply has been added while he was editing and is asked to confirm he still wants to post. He confirms, and is returned to the topic display with his reply added to the end. He returns to the forum. The topic just added is not highlighted, since the change was made by him.

Now, this may be more functionality than you want to consider. But if you did want to support it, it would affect your design (obviously). My point is that you have to determine the use-cases, the functionality to be supported, in order to say whether a design is even adequate or what it is missing, or what it will make difficult to implement.

From the scenario above, we can pull out some use cases. We can also identify what needs to go into the domain model - users, forums, topics, replies, but also some of the attributes of those - last modified dates - and operations (list of forums by categoy, list of topics per forum in date order etc).

I would suggest concentrating on identifying the key domain objects and operations first, as that lets you defer decisons. For instance, you will need an operation "is topic modified since last visit from user" but you don't need to decide yet whether topics know which users visited when or whether users know which topics were visted when. Indeed, if your high-level/interface design only specifies operation, which one you use can be an implementation detail and can be changed at any point without affecting much else.

Assuming your question derived from the wording of the assignment, note you said

"What classes and functions will it have. "

. Not what fields will the classes have, although that's mostly what your code in the question covers. So the assignment is asking you to on what are the key objects, of what types, and what will need to be done with them

If I get time, I may come back and braindump some design thoughts, but (as I'm assuming this is an assignment) it would be better if you thought things through.

Upvotes: 3

Daniel Fath
Daniel Fath

Reputation: 18069

I think, the first thing to start would be usecases. What features do you intend to support? After that you can think about the classes you want to make.

On a glance the thing that comes at me is how come message isn't an Object. If it was an object it would be way easier to manipulate (for example deleting or hiding would be way more elegant). However since I don't know your use case I'm not sure how that works.

Also your Topics and Forums should be in Many-To-One relationship if you want Forums to contain Topics. Again I'm not sure about your use cases but one suggestion would be to give each forum a list of sub-forums (i mean Forum[] subforums) and an optional link to higher forum. so you could organize your forums hierarchically.

Upvotes: 0

duffymo
duffymo

Reputation: 308753

Yes, I'd recommend that you add some relationships to these objects. I would have expected Forum to have collections of Users and Topics, because only one of each won't be interesting.

Upvotes: 0

Related Questions