Problem Statement: Design a StackOverflow
Functional Requirements:
1. User Management
• User’s can register and login
• Users can have roles such as User, Moderator, Admin.
• Guest can browse questions and answers.
2. Questions and answers
• Registered users can post the questions.
• Users can answer the questions.
• Questions and answers can be upvoted or downvoted.
• Users can mark an answer as accepted.
3. Tags and Categories.
• Questions can be tagged with relevant topics.
4. Search
• Users can perform a global search across questions and answers.
5. Notifications
• Users receive notifications for activities on their questions and answers.
6. Feed View
• Options to view recent questions in the feed.
• Options to view most upvoted questions in the feed.
7. Moderators can close or reopen questions.
Non-functional Requirements:
1. Availability
2. Latency
3. Durability
4. Performance
Actors:
1. Guest
a. Role: A user who is not registered or logged in.
b. Responsibilities:
i. Can browse and search for Questions and Answers.
ii. Can register and become a registered user.
2. Registered User
a. Role: A user who registered and logged into the system.
b. Responsibilities:
i. Can ask questions and provide answers.
ii. Can upvote, downvote and mark answers as accepted.
iii. Can follow tags and receive updates.
iv. Has a personalized feed with recent and upvoted questions.
v. Receives a notification for activities on their questions and answers.
3. Moderator
a. Role: A user with additional privileges to moderate content.
b. Responsibilities:
i. Can close or reopen the questions.
ii. Has the authority to moderate questions and answers.
4. Admin
a. Role: System Administrator with overall control.
b. Responsibilities:
i. Manages user accounts, roles and permissions.
ii. Manages System setting and configurations.
Use Cases:
1. Browse Questions and Answers:
a. Every user can browse the questions and answers.
2. Ask Questions
a. Actors: Registered user can ask questions on various topics, seeking help or information from the community.
3. Answer Questions
a. Registered users can provide answers to questions asked by others , sharing their knowledge and expertise.
4. Upvote/Downvote
a. Registered users can express their opinion on the quality of answers by upvoting or downvoting them.
5. Mark answer as accepted
a. User who asked the question can mark one answer as accepted, indicates that it solved their problem.
6. Follow tags
a. Users can follow specific tags to receive updates on questions which are related to those topics.
7. View Feed
a. Users have a personalized feed displaying recent and upvoted questions based on the tags they have.
8. Moderate content
a. Provides moderators with the ability to moderate and manage questions and answers , including closing or reopening of questions.
9. Manage System Setting
Use Case Diagram:
Class Diagram:
Code Implementation of Design Patterns:
1. Factory Method
interface IQuestionFactory {
IQuestion createQuestion(String title, String content, IUser user, List<ITag> tags);
}
class QuestionFactory implements IQuestionFactory {
@Override
public IQuestion createQuestion(String title, String content, IUser user, List<ITag> tags) {
return new Question(title, content, user, tags);
}
}
2. Observer Pattern
//Observer Interface
interface IQuestionObserver {
void update(IQuestion question);
}
//Concrete Observer
class Feed implements IFeed {
// Other Feed properties and methods...
@Override
public void update(IQuestion question) {
// Logic to update Feed based on new Question
System.out.println("Feed updated with new question: " + question.getTitle());
}
}
//Concrete Subject
class Question implements ISubject {
// Other Question properties and methods...
@Override
public void addObserver(IObserver observer) {
observers.add(observer);
}
@Override
public void removeObserver(IObserver observer) {
observers.remove(observer);
}
@Override
public void notifyObservers() {
for (IObserver observer : observers) {
observer.update(this);
}
}
}