I was given a Use Case for a Quizz Application. The Use Case is only for creating new Quizzes. I am having trouble deciding which design is better:
a)
b)
Although this might look like a Domain Model, it is in fact a Class Diagram (I was lazy to put the methods/attribtues in the diagrams :( ).
The idea behind all this is that I have a QuizCatalog
that has Quiz
zes. Each Quiz
has a set of Question
s, that must be created through a QuestionFactory
(a Question
is an abstract class, and QuestionA
, QuestionB
, etc are the concrete classes). Each Question
has a set of PossibleAnswers
.
The difference in terms of associations between Design A
and Design B
is that in the first I am considereing that CreateQuizController
will simply delegate every task it has to QuizCatalog
. If QuizCatalog
needs to do something, it will delegate everything it might need down the hierarchy. This is actually nice, as it seems to reduce coupling.
Design B
, on the other hand, follows a different philosophy. The associations seen in Design A
still exist (as a QuizCatalog
still has Quiz
zes, a Question
PossibleAnswer
s, etc) but now I've made CreateQuizController
have access basically to every kind of object in the domain it might need to create in the process(I've signaled those kind of associations with d
). The idea is that instead of asking the QuizCatalog
to create a Quiz
, CreateQuizController
will create a Quiz
by itself (and if it needs to create Questions for the Quiz
, it will by itself, the same happening for Question
's PossibleAnwser
s, etc).
There are 2 things that bother me about Design A
:
1.
If I need to create temporary objects that need to be filled up before being put "in the system" (for example, a Quiz
is only actually added to QuizCatalog
after it was filled with all the wanted Question
s), following this design I'll have to keep them in some place other than the Controller
.
For example, when I first create a Quiz
, I'll have to probably save it under QuizCatalog
without actually adding it to the current collection of Quizzes that is accessible to the rest of the system. I find this kind of behaviour a bit awkward. I find it better to keep those kind of temporary objects in a Controller
, as if anything wrong happens then the "System" is kept just as it was before, with no problems associated.
The problem is that it makes the Controller
have to know about almost everything, which might be undesirable. On the other hand, there is no difference in how coupled the rest of the classes in the System
are.
2.
If I am going to use Design A, I actually don't see a big point in having a CreateQuizController, as basically everything can be done by just having a reference to QuizCatalog. In my eyes, it is just delegating all its work to QuizCatalog, so why have it in the first place?
Also, using Design A
, I'd probably consider QuestionFactory
to be a Singleton, while if using Design B
I'd probably just have CreateQuizController
's constructor accept an instance of a QuestionFactory
instead.
What are your thoughts about this?
Thanks
PS: Only after drawing the diagrams I noticed that Quizz has 2 z's :( My bad.