Question/Answer for multiple Users – How should I design it?

I’m wondering about a good way to deal with a Question/Answer – Model for multiple Users.
My goal is to have an efficient and readable model where all the results of my users are stored. Every user has the same questions/answers!

At the moment I have three classes, Question,Answer and User.

A user has a Set of Questions.
A question has a Set of Answers and an extra field selected_value which is the answer the user clicked.

Every user has a copy of the same set of questions. Therefore I can easily see what a user has clicked.

This is an unnecessary overload because I need to store the questions/answers more than once.

But the good thing about this approach is the availability of my questions/answers in my user-model as I need to see what every user clicked. It’s also easy to extract this information (e.g. via xml) doing just a loop around every user and his questions.

But what kind of approach would you recommend to use? Should I create a model “result” inside of my User-Model where I simply store a list of pairs like “QuestionId, AnswerId”? Is there any more accepted way to do so?

3

A User may take many Sets of Questions, at different times or even more than once – I think you need a new class here to store:

(a) The association of a User with a Set of Questions (Quiz?), possibly at a particular time, and

(b) The answers selected by that User for that particular Set of Questions.

I would consider a new class, created based on the data within a Set of Answers and containing a new field called, say, Chosen_Answer. In this way, the Sets of Answers class itself stays clean, self-contained and, most importantly, exists independently of any particular User, so you don’t need duplicated copies any more. When a User takes a Set of Questions, you create a new instance of this new class in which to hold their responses.

Since it looks like the questions and the set of possible answers are the same for all users, I would say that it is fine if you share the same data with all the users. You can use composition for this.

The only piece of data that varies according to your descriptions is the user’s selected answer for every question. As such, a user may have another collection data structure to store the selected answer per questions, somewhat like

class User{
  private final List<Question>; 
  private final Map<Question, Answer> answers;

  public User(List<Question> questions){
      //shared by all users
      this.questions = questions;
      //an instance per user
      this.answers = new HashMap<>();
  }
}

When it comes to storage, the map of answers will probably be just a table (or document, file, store,etc.) containing the IDs of the questions and the ID of selected answer for a given user.

+-----------------+
| selected_answer |
+-----------------+
| user_id  <pk>   |
| quest_id <pk>   |
| ans_id   <pk>   |
+-----------------+

Doing so, avoids repetition in both memory and storage.

When you design a DB you may want to keep it normalized I.e. stay out of duplicates so that update queries will run faster and in a safer way. This is not the only approach as you might want to de-normalize your tables so that read queries will run faster (more suitable for BI). The point is that there’s no right or wrong- both are fine depending on your needs.

Regarding your case- if the quantities we are talking about here are not large, and performance is not an issue, I would go with storing only a representation of the selected answer in your user object (maybe an id or an answer object). It will make things easier and simpler. Things you should consider are CRUD operations and their frequency- how frequently do you change the text of an answer? A question? How frequently does the selected answer changes if ever? And so on..

One more thing- keeping your domain objects design synchronized with the actual db design is not a must so you may have one normalized and the other de-normalized.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Question/Answer for multiple Users – How should I design it?

I’m wondering about a good way to deal with a Question/Answer – Model for multiple Users.
My goal is to have an efficient and readable model where all the results of my users are stored. Every user has the same questions/answers!

At the moment I have three classes, Question,Answer and User.

A user has a Set of Questions.
A question has a Set of Answers and an extra field selected_value which is the answer the user clicked.

Every user has a copy of the same set of questions. Therefore I can easily see what a user has clicked.

This is an unnecessary overload because I need to store the questions/answers more than once.

But the good thing about this approach is the availability of my questions/answers in my user-model as I need to see what every user clicked. It’s also easy to extract this information (e.g. via xml) doing just a loop around every user and his questions.

But what kind of approach would you recommend to use? Should I create a model “result” inside of my User-Model where I simply store a list of pairs like “QuestionId, AnswerId”? Is there any more accepted way to do so?

3

A User may take many Sets of Questions, at different times or even more than once – I think you need a new class here to store:

(a) The association of a User with a Set of Questions (Quiz?), possibly at a particular time, and

(b) The answers selected by that User for that particular Set of Questions.

I would consider a new class, created based on the data within a Set of Answers and containing a new field called, say, Chosen_Answer. In this way, the Sets of Answers class itself stays clean, self-contained and, most importantly, exists independently of any particular User, so you don’t need duplicated copies any more. When a User takes a Set of Questions, you create a new instance of this new class in which to hold their responses.

Since it looks like the questions and the set of possible answers are the same for all users, I would say that it is fine if you share the same data with all the users. You can use composition for this.

The only piece of data that varies according to your descriptions is the user’s selected answer for every question. As such, a user may have another collection data structure to store the selected answer per questions, somewhat like

class User{
  private final List<Question>; 
  private final Map<Question, Answer> answers;

  public User(List<Question> questions){
      //shared by all users
      this.questions = questions;
      //an instance per user
      this.answers = new HashMap<>();
  }
}

When it comes to storage, the map of answers will probably be just a table (or document, file, store,etc.) containing the IDs of the questions and the ID of selected answer for a given user.

+-----------------+
| selected_answer |
+-----------------+
| user_id  <pk>   |
| quest_id <pk>   |
| ans_id   <pk>   |
+-----------------+

Doing so, avoids repetition in both memory and storage.

When you design a DB you may want to keep it normalized I.e. stay out of duplicates so that update queries will run faster and in a safer way. This is not the only approach as you might want to de-normalize your tables so that read queries will run faster (more suitable for BI). The point is that there’s no right or wrong- both are fine depending on your needs.

Regarding your case- if the quantities we are talking about here are not large, and performance is not an issue, I would go with storing only a representation of the selected answer in your user object (maybe an id or an answer object). It will make things easier and simpler. Things you should consider are CRUD operations and their frequency- how frequently do you change the text of an answer? A question? How frequently does the selected answer changes if ever? And so on..

One more thing- keeping your domain objects design synchronized with the actual db design is not a must so you may have one normalized and the other de-normalized.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Question/Answer for multiple Users – How should I design it?

I’m wondering about a good way to deal with a Question/Answer – Model for multiple Users.
My goal is to have an efficient and readable model where all the results of my users are stored. Every user has the same questions/answers!

At the moment I have three classes, Question,Answer and User.

A user has a Set of Questions.
A question has a Set of Answers and an extra field selected_value which is the answer the user clicked.

Every user has a copy of the same set of questions. Therefore I can easily see what a user has clicked.

This is an unnecessary overload because I need to store the questions/answers more than once.

But the good thing about this approach is the availability of my questions/answers in my user-model as I need to see what every user clicked. It’s also easy to extract this information (e.g. via xml) doing just a loop around every user and his questions.

But what kind of approach would you recommend to use? Should I create a model “result” inside of my User-Model where I simply store a list of pairs like “QuestionId, AnswerId”? Is there any more accepted way to do so?

3

A User may take many Sets of Questions, at different times or even more than once – I think you need a new class here to store:

(a) The association of a User with a Set of Questions (Quiz?), possibly at a particular time, and

(b) The answers selected by that User for that particular Set of Questions.

I would consider a new class, created based on the data within a Set of Answers and containing a new field called, say, Chosen_Answer. In this way, the Sets of Answers class itself stays clean, self-contained and, most importantly, exists independently of any particular User, so you don’t need duplicated copies any more. When a User takes a Set of Questions, you create a new instance of this new class in which to hold their responses.

Since it looks like the questions and the set of possible answers are the same for all users, I would say that it is fine if you share the same data with all the users. You can use composition for this.

The only piece of data that varies according to your descriptions is the user’s selected answer for every question. As such, a user may have another collection data structure to store the selected answer per questions, somewhat like

class User{
  private final List<Question>; 
  private final Map<Question, Answer> answers;

  public User(List<Question> questions){
      //shared by all users
      this.questions = questions;
      //an instance per user
      this.answers = new HashMap<>();
  }
}

When it comes to storage, the map of answers will probably be just a table (or document, file, store,etc.) containing the IDs of the questions and the ID of selected answer for a given user.

+-----------------+
| selected_answer |
+-----------------+
| user_id  <pk>   |
| quest_id <pk>   |
| ans_id   <pk>   |
+-----------------+

Doing so, avoids repetition in both memory and storage.

When you design a DB you may want to keep it normalized I.e. stay out of duplicates so that update queries will run faster and in a safer way. This is not the only approach as you might want to de-normalize your tables so that read queries will run faster (more suitable for BI). The point is that there’s no right or wrong- both are fine depending on your needs.

Regarding your case- if the quantities we are talking about here are not large, and performance is not an issue, I would go with storing only a representation of the selected answer in your user object (maybe an id or an answer object). It will make things easier and simpler. Things you should consider are CRUD operations and their frequency- how frequently do you change the text of an answer? A question? How frequently does the selected answer changes if ever? And so on..

One more thing- keeping your domain objects design synchronized with the actual db design is not a must so you may have one normalized and the other de-normalized.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật