Project Solution: Education Assessment Class Diagram
Next on our list of solutions is our class diagram.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

large

Now, this diagram is really not as complex as some of the other ones we've done in this course so far mainly because I wanted you to focus on one very specific topic and that is a polymorphic Association. Now that may sound like a really scary word and that's part of the reason why in the requirements video I instructed you to go and research what polymorphic associations are. So that you can learn how to integrate them here in the system. So that's really what we're going to focus on before we get to that. I want to show and point out a couple key components on the solution that we have here and also that you have access to in the solution file. And that is how we can represent some of these associations in a little bit of a different way. And so I'm using this as a case study. I am not saying that you needed to build the solution exactly like this. One goal with this course is not only to teach you how to build UML diagrams to solve problems it's also to help you recognize all of the different kinds of UML diagrams and elements that you may see in your day to day jobs.

So here because this guide is all about associations. I wanted to point out a few ways that those could be visualized. Right here we have a very basic one. This is just a line connecting one class to another in this case.

large

We have a quiz which is connected to a result and also notice, I'm not adding any multiplicity here or anything like that. If you did that's fantastic I just didn't want to clutter up the diagram because I wanted this guide to focus completely on how we can visualize polymorphic kind of associations. But right here this is a line, now this is perfectly valid UML. You could create a full set of class diagrams that have no arrows. Nothing like that and they only have straight lines that are connecting from one class to another and that is perfectly valid.

Now another way that you could do it is with these type of arrows.

medium

Now I highly doubt anyone going through this course will have added that to the solution. And I rarely add these either. These are composition connectors so whenever you see one of these big black diamond type of arrows that means that whoever created the diagram is wanting to illustrate that there is a composition type of association here and if you're unfamiliar with the concept of composition what it essentially means is that it represents a whole part type of relationship. So in this case we have a class which has an association with a grade and the grade cannot exist without a class and then we also have projects associated with the class. Now this is not so much to say that I wanted this to be in anybody's solution in a real world scenario. I probably would not even add that to my own diagram.

But when ever you're reading someone else's diagram there's a chance you're going to run into these and so I wanted to include them in at least one of these solutions just so you can know what they are and because I know those do look a little bit odd.

Now, know moving all the way here this is now going to start getting us into what this guide is all about which is polymorphic associations.

When ever you see an arrow that is completely empty like this

medium

or it's just like this white triangle pointing at an element what that represents is a generalization type of association and that is essentially what a polymorphic association is. So right here I think we have a good case study. We have a user and then it has two types of associations it has a student and a teacher. Now these both are pointing to the user with this type of Arrow because these are generalizations. A student is a user. A teacher is also a user. And so they have their own kinds of unique characteristics. A student can have a grade. They can take quizzes whereas a teacher needs to have their degree diploma and different elements like that added.

Now moving all the way over here we have a second type of solution for integrating polymorphism and that is dealing with our questions. So we have a question here that has a description a right answer and different elements like that. And then it has a couple of different types of associations and this is literally taken verbatim from the class diagram that is used for devcamp because devcamp in its mid-term and final module has a concept of exam questions and then those questions have multiple types it has a multiple choice option and then an essay option.

And so these are both classes and they're both types of questions but they have their own unique characteristics a multiple choice type question can have a description and then it can have all kinds of different options and I don't have a secondary table showing options but in the devcamp code I do have another table called Options that stores the options for each multiple choice question and then that is how multiple choice questions are generated. Now with essays this only has a description and then it does have a right answer but it's not automated. So we have right answers that are placed in the system and they give some guidance for the instructors but there's no way of just saying that a essay question is correct or incorrect so it's a completely different type of setup. This also will change the way that the page loads because if it's an essay question then a large window for them to type code or their full answer is going to appear instead of the multiple choice options. So these are both types of questions but they're stored completely differently because even though they need to represent a question they have very different tasks in how they perform that job.

Lastly one of the most important components on having a Polymorphic Association is that both of these classes. Both of these when they get instantiated and they become objects they can be treated the same way. So our student and teacher can't really be treated the same way. So this is a pure polymorphic kind of system. It has a number of characteristics of a polymorphic Association. However what we have with our questions with multiple choice and essay. These are a very pure form of the polymorphic association and the reason is because of this answer right here. So in order to have a true polymorphic Association what it means is that you can treat each one of these items exactly the same way. So an answer can be its own class its own table and it can interact with multiple choice an essay in an identical manner and that is very important because if we had to build different types of work arounds for multiple choice and essay then what happens if we start to add additional question types?

All of a sudden this answer class is going to start to get very very messy. But by being able to integrate a polymorphic association it leaves the system in a position where it can be very scalable. We can add as many types of questions as we want and then we can build each of them to be their own polymorphic type of association and then answer can simply work the same way that it always has. And so thats one of the reasons why polymorphic associations are considered a more advanced topic in database design and in application development.

But they are very powerful and so its something that I wanted you to research and learn. And then also learn how to model just like we did right here.