Design / Object Classes
A Design Class diagram is a way of modelling the domain to a level of detail much more than that of a domain model. Inside a design class diagram, the classes become objects – Object Classes:
Objects are created according to an Object Class Definition. An Object Class definition is both a type and a template for creating objects. It includes declarations of all the attributes and operations that should be associated with an object of that class.
Ian Sommerville- Software Engineering Edition 8, 2007- Page 316, Ch 14.1
In UML an object class is represented as a named rectangle with 2 sections – the object attributes and the object operations. An example of this is shown below using an object class that models a Circle / Rectangle and a Student:
If one was to thing of this in an Object Oriented way, then the top section would be the declaration of variables, and the bottom section the functions/methods.
Design Class Diagram Example
Now, this is going to get bog, fast – just a warning, hehe. Now for this part, you will need to read this:
An exam contains 3 different types of questions:
- Plain text questions
- Multiple choice questions
- Composite questions
Using this, draw a Domain Model and then a Design Class Diagram for that Domain.
First things first is that we need to identify the Classes. Well, quite obviously we have 3 Classes straight of the top:
- Plain text questions
- Multiple Choice questions
- Composite questions
BUT, look more closely… what do you see? Well, if you saw it or not, they all inherit something - that's right, they all inherit “Question”, think about it, each one will contain something of the same variables and operations etc etc, and we really don't want to write out the same variable/operation declaration 3 times?!
But then.. what about Multiple Choice questions? They contain multiple answers, so surely we need a type for that – so we could use “Multiple Choice Question Options”
That means we now have 5 classes! :
- Questions
- Plain Text
- Composite
- Multiple Choice
- Multiple Choice Option
:)
So for quick guidance, here is what the Domain Model will look like:
Here, Plain Text, Multiple Choice and Composite all inherit Question. Aside from this Multiple Choice Questions contains Multiple Choice Options; and Composite Questions contain more Questions.
Note: (A) here means that “Question” is Abstract
Extra Features
hmmm… I just realised, i missed something up above – im sooo sorry :(
So, yeah, there are some extra features inside of a Design Class Diagram – besides the bleeding obvious… These extra features i forgot to mention are:
- Visibilities. The variables and operations all have visibilities, these are:
- + (public)
- - (private)
- # (protected)
- ~ (package)
I think that’s it… if it isn’t than either leave a comment, email me or if your at my uni then just come bother me, hahaha :D
Design Class Diagram Example – Finally…
OK, so here we go! Using the Domain Model up above, here is the Design Class Diagram for that Domain Model! :
This all looks good, but take a look at Plain Text and Multiple Choice. They both have a field called “+marksAllocated: int”. So we could refactor some here and make the diagram a little neater:
**If you see a spelling error, it will more than likely be “Reactor” – stupid Windows Live Blogger making the word “Refactor” into “Reactor” :(
[...] Design Class Diagrams [...]
ReplyDelete