Thinking process behind designing a UML class diagram
Oh wait… If you’re here to learn anything about UML itself, then you’ve come to the wrong place. Watch the below video for that. It’s the best tutorial on creating UML class diagrams I could find. It explains about most of the characteristics of UML class diagrams, simply in 10 minutes (You’re a freak if you can sit through a tutorial on this topic for more than that 😒). If you’re more into reading, look into this article instead. It goes over more detail on this subject.
Ah.. You’re still here?! Then I guess it wasn’t UML you had issues with. You already knew how to draw UML class diagrams, it’s just that you don’t know how to design one to suit your project (Like.. you have no idea what classes should be there in the diagram since you haven’t even started the implementation). Most probably you only had to design UML diagrams for assignments you were given at your university, where everything you need to know about classes and functionalities of the program you had to create was elaborated by the lecturers themselves. But now, since you have to figure everything out by yourself as you are working on a project of your own for the first time, you had to come here (No shit Sherlock 😑). So.. without further ado, let’s get right into it.
Well, the very first thing you should do, which you might have done already, is create the classes you’re 100% sure that you would need in your project when you start implementing (Think about the main functionalities here). I’m talking about the type of classes that are like the elephant in the room i.e. Animal class in a Zoo System, Book class in a Library Management System, User class if there is a login functionality… you get the idea, right? If you’re not quite sure about the attributes and methods that should be included in these classes, forget it. Just add some obvious ones for now. You would have a better idea about what’s to add after you’ve designed all the classes.
Ok.. so what you should do after that is analyze the flow of the program or the application you are developing in detail. What I mean is think about what is happening throughout your program from the beginning to the end. One of the main reasons for being stuck when designing these diagrams is not having a proper idea on the procedure of your program. Yes, you might have an understanding of the idea behind the project as a whole, but to design these kind of diagrams you have to be able to explain the whole process of the application, step-by-step. If you’re working on a group project, before doing anything else, discuss about this if you haven’t already. It’s always a good idea to note down the points after you’ve come to a conclusion about the flow of the program you’re developing (So you can avoid the rookie mistake where you start to work on a different idea down the line because you forgot what the initial idea of the project was after a couple of months. Never happened to me in my first ever group project 🙄🥱).
Then what you have to do is create necessary classes that you think you would need for the implementation, for each step of the program. This is why resolving the flow of the application is very important because it’s easier to figure out the components in a class diagram when you think about each step of the process of the program, separately. You should add the corresponding relationships along the way as it might not be too much of a problem, since you have a proper understanding about the whole process of the program now (I’m not going to talk about what type of relationship should be used for each step or anything about UML in that regard, as I mentioned in the beginning, that’s not the goal of this article). What you should understand is you are free to do anything when it comes to the components of the diagram (as long as you abide UML principals), as you’re the one who is going to use it to make the implementation part of the project easier and more efficient. So you can make necessary adjustments yourself if you feel like it’s the best way to implement the program. After you are done with all the components in the class diagram, you should go through each step of the program again to make sure you haven’t missed anything. If you’re working in a group, have a brainstorm session to examine each and every component in the designed class diagram before finalizing it. And… that’s pretty much it. Still have doubts? Don’t worry. I will demonstrate designing a class diagram from the way I discussed, taking a project I’m currently working on as an example.
The project is about a mobile application where it recommends furniture items, analyzing the surrounding the user is in. So there should be a class called Furniture Item for sure (The elephant in the room 🐘😜). We haven’t decided to add user login functionality, or any of the features you see in an online store for now, so I don’t have to create classes related to those aspects. Then it’s time to go through each step of the application one by one, creating classes for each one as necessary (I will only talk about the functionalities of the application that is relevant to the topic, so won’t go into much details technical wise).
First the user has to take an image of the area he or she wants a furniture item to be placed. So I think a class to store that image and other input data would come in handy. Then the system would analyze the image and detect the objects that are already there, determining the furniture category most of the objects falls into. Therefore, we might have to have a class called Category. After the system has decided on the category of furniture, it will show the user a specific furniture item from that category as his or hers preference. Therefore, it is obvious that we would need a class to assign data for that output. I assume that it’s better to create another class called Color, which we would need to detect the colors of the image and assign a particular color from those to the output object. You can see below a draft of the class diagram for this application which I designed in the way I described.
It wasn’t that complicated, was it? Of course the above design is not the final class diagram for the fully implemented application, but it is good enough for us to have an idea to start the implementation and also show it to someone else to explain the functionality of the application, even if he or she isn’t an expert on the technical side of these things (Isn’t that the whole purpose of a class diagram in the first place 💁♂️). If you can describe about your project just by showing your class diagram, I think that is more than enough for a start. Well.. I guess I have pretty much talked about everything that’s needed to be said about this topic. It certainly took longer than I expected (That’s what she said 😏). Ugh.. I’ll see myself out. All the very best on your project. 😊💕
P.S. I thought of telling you about some of the tools to design UML diagrams as well. draw.io is a simple online tool if you only want to design a draft . But as I heard it’s not used in the industry as much, so I wouldn’t recommend it for academic work. StarUML is the one I used to design the above diagram. It’s the best UML tool I have used up to now. Heard good things about Visual Paradigm too, but haven’t used it myself. Give it a try if you don’t like StarUML. Good luck!