UML Class Diagram Tutorial

a chart that shows the relationship of each part to a whole. This is a topic that many people are looking for. is a channel providing useful information about learning, life, digital marketing and online courses …. it will help you have an overview and solid multi-faceted knowledge . Today, would like to introduce to you UML Class Diagram Tutorial . Following along are instructions in the video below:

“My name is zach and i m with lucidchart today. I ll be teaching you you about uml class diagrams. We ll start with some of the basic characteristics. Then ll talk about relationships and we ll finish up by going through some nexamples together alright.

Let s talk about some of the basic ncharacteristics of class diagrams to help explain these characteristics. I m ngoing to make up an example to help illustrate so let s say we re building a system for na zoo and by the way these examples. I m going nto use probably wouldn t ever find their way into an actual program. But it ll make nall these concepts easier to understand so in our zoo.

We d want to describe the ndifferent things that are in the system you represent those things through classes. Nand. A class is depicted with this shape. Here.

So what s in a zoo well there are a ton of animals. So we could create a class for our animals to do that you just write the name of the nclass in this top section. If our class is animal an instance of that nclass would be a specific animal. So the question is how would you go about nidentifying each instance of that class you do that through attributes.

An attribute is a significant piece of data ncontaining values. That describe each instance of that class. They re also known as fields variables. Nor properties and they go in the middle section.

Here. So for our animal class. We could create attributes nlike name id and age that way. We could identify a specific instance.

Nof. The animal class. Like ruth id. Number 304 age 114.

These need to be formatted. A certain way. Though you start with visibility. Which we ll talk nabout later the name of the attribute beginning with a lowercase letter.

Then you follow it with a colon and the data ntype for the name we d want to return a string and we can format the other attributes. The nsame way except that we d want to return an integer since these are numbers now that we ve got some attributes for our nanimal class. We get to the bottom section. Here.


This is where you put methods. Which are also nknown as operations or functions methods. Allow you to specify any behavioral nfeatures of a class. So we might ask ourselves what are some different nbehaviors of this animal class.

Maybe we d want to be able to change our nanimals names. Like ruth should actually be called rita. So let s create a function called set name. We could also create a method for eating nsince all of our animals.

Eat methods also need to be formatted a. Certain way you start with visibility which. We ll talk nabout next . Then the method beginning with a lowercase letter.

Next you put parentheses to signify the function nyou re going to program. Later you can also add variables. And the data type nin here. But in most cases.

It s not really necessary we ll add visibility and parentheses to nthe eat method as well now let s talk about the visibility. The visibility of an attribute or a method nsets the accessibility for that attribute or method. So right now. We have a minus sign for all nof these.

Which indicates that each of these attributes and methods are private. They can t be accessed by any other class nor subclass. The exact opposite is the plus sign which nmeans an attribute or method is public and can be accessed by any other class. Another visibility type is indicated by the nhash.

Which means an attribute or method is protected these can only be accessed by the same class nor its subclasses and finally there s the tilde or the squiggly nas i. Like to call it this sets the visibility to package or default nwhich means. It can be used by any other class as long as it s in the same package. But that one is rarely ever used in most cases.

Your attributes are going to nbe. Private or protected and methods are often public. Let s quickly review these basics with another nexample let s make a class for employee. We could give an employee attributes like name employeeid phone number and department.

We ll want all these attributes to be private and then we could create a simple method nlike updating the phone number which we ll go ahead and set to public. So you may have noticed that i m using diagramming nsoftware to create these uml class diagrams. The same principles apply. If you re using npen and paper.


But a diagramming software makes it much easier the diagramming software. I m using today is nlucidchart and you can sign up for free by clicking on nthe link at the top right all it takes is an email address and then nyou ll be able to follow along as we make these class diagrams. So the next thing. We ll need to cover are nthe different relationships that exist between classes the first type of relationship that we ll ndescribe is inheritance and i m gonna keep going with the zoo example nbecause.

It makes it easy to understand the logic of these relationships. We ll get to a more technical real world nexample later okay so inheritance let s say in our zoo. The only animals we nhave are tortoises otters and the lesser known but nonetheless amazing slow loris in our system. We want to distinguish each nof them as their own class.

So we make three new classes for tortoise notter and slow loris and i ll make these a little smaller. So nyou can see them better now instead of duplicating attributes for nname id. And age we can make these classes into subclasses of the animal class by drawing nopen arrows like this this is an inheritance relationship. We re saying that these subclasses inherit nall.

The attributes and methods of the superclass you could also use the terms child and parent nclass. So our otter class is going to inherit the nattributes of name age and id. And then we could add an attribute specific nto otter. Like whisker length.

One of the advantages of inheritance is that nif. We wanted to change or add an attribute for all animals. We wouldn t have to go nin and make that change to tortoise and then otter and then slow loris. We just make the change to the animal class nand.

It applies across all subclasses in this scenario. We also have what s called nabstraction animal is an abstract class because in our system anytime. We want to ninstantiate one of our classes. It s going to be a tortoise otter or slow loris.

We wouldn t instantiate the animal class nitself. The animal class is just a way to simplify nthings and keep the code. So you don t repeat yourself so to show that this is an abstract class nwe. ll put the name in italics you could put the class name inside these nthings as well.

But i prefer italics okay another type of relationship is association. So if we had a class for sea urchin. We could ndraw an association. Which is just depicted by a simple line between otter and sea urchin and we could say otter eats sea urchin there s no dependency between them.

It s just a basic association relationship nand. It s pretty simple the next type of relationship is aggregation. It s a special type of association that nspecifies a whole and its parts so to continue with our. Zoo exampleagain nthis is just to help explain the.


Logiclet s create a new class for a group of tortoises. A group of tortoises is called a creep and nthat s pretty cool so here s our creep class. And it s got na relationship with tortoise. Any of our zoo s tortoises could be part nof a creep.

But they don t have to be a tortoise could leave the creep at any point nand still exist on its own that type of relationship where a part can nexist outside the whole is aggregation. And we note it with an open diamond. There s also a relationship where the part ncan t exist outside the whole. It s called composition to illustrate this i m going to create na.

Few new classes let s just say we have several different nvisitor centers in our zoo and each of those visitor centers has a lobby nand a bathroom. Now if one of our visitors centers was torn ndown. The lobby and the bathroom of that visitor center would be destroyed as well those rooms couldn t exist apart from the nvisitor center that they re in that s. Compositionwhen a child object nwouldn t be able to exist without its parent object.

We note. A composition relationship with a nclosed diamond. Another important concept when talking about nrelationships in uml class. Diagrams.

Is multiplicity multiplicity allows you to set numerical constraints non your relationships for example. Let s say we want to specify nthat. Our visitor centers are going to have just one lobby. We simply write the number one here meaning nthere can be one and only one lobby per visitor center.

But for bathrooms. Maybe we want to make it nso that there s at least one bathroom per visitor center. But leave the option to have nas many as you d like we d use this notation to denote one or nmany bathrooms. Other types of multiplicity are zero to one nwhich is an optional relationship n.

Representing a specific amount which in nour example was one. But it could be any other number depending on your use case zero to many one to many or a specific number range hopefully. Our zoo examples have helped explain nthose concepts. But i want to show you what a real world example would look like this is a uml class diagram for an online.

Nshopping cart and if you want to look at this diagram with me just click the link nin. The top right corner. You can see that this system has several classes nand relationships. So let s walk through a couple of them we ll start with the user class.

It s got attributes for user id. Password nlogin status and register date you ve got the different return types on nthe right and on the left. The visibility. Which are set to private you can see how the values returned by these nattributes would specifically describe an instance of the user class down below.


We have a public method of verify nlogin returning a boolean and this makes sense right methods are behaviors of a class. So if you were to log in to your user. Account nthere s. A function in place that verifies your login credentials.

Let s move on to the customer class. This arrow. Tells us that customer is a child nof user so customer inherits. All the attributes and nmethods of the user class and same thing for the administrator class both of these inherit from user.

But also nhave their own specific attributes and methods like administrator can update catalog but ncustomer can t stemming from customer there are several nlines with the closed in diamond. So if you recall these are composition. Relationships nwhich means that the parts cannot exist. Without the whole.

If an instance of the customer class. If that ncustomer s account was destroyed his shopping cart would be destroyed and his orders would nbe lost. They can t exist outside of the customer. The same applies for shipping info and order ndetails.

If there s no order. There s not going nto be any order details or shipping info. The last thing we ll look at in this example. Nis multiplicity.

You can see that a customer can have zero. Nor. Many orders makes sense right you could create a customer account for an nonline store. But never buy anything or you could be a frequent customer and place nseveral different orders and then on the flip side an order can belong nto.

Only one customer. It d be pretty confusing. If a specific order nwith. A unique order id was duplicated across several different customers.

And here. You can see a one to one relationship. Each order has one and only one order details and order details belongs to one and only none order thanks for watching this tutorial on uml class ndiagrams be sure to subscribe to the channel and leave na comment below lastly. Don t forget to sign up for a free nlucidchart account by using this link.

” ..

Thank you for watching all the articles on the topic UML Class Diagram Tutorial . All shares of are very good. We hope you are satisfied with the article. For any questions, please leave a comment below. Hopefully you guys support our website even more.

“Learn how to make classes, attributes, and methods in this UML Class Diagram tutorial. There s also in-depth training and examples on inheritance, aggregation, and composition relationships.nnUML (or Unified Modeling Language) is a software engineering language that was developed to create a standard way of visualizing the design of a system. And UML Class Diagrams describe the structure of a system by showing the system s classes and how they relate to one another.nnThis tutorial explains several characteristics of class diagrams. Within a class, there are attributes, methods, visibility, and data types. All of these components help identify a class and explain what it does.nnThere are also several different types of relationships that exist within UML Class Diagrams. Inheritance is when a child class (or subclass) takes on all the attributes and methods of the parent class (or superclass). Association is a very basic relationship where there s no dependency. Aggregation is a relationship where the part can exist outside the whole. And finally, Composition is when a part cannot exist outside the whole. A class would be destroyed if the class it s related to is destroyed.nnFurther UML Class Diagram information: nnLearn more and sign up:nhttp://www.lucidchart.comnnFollow us:nFacebook: nnCredits for Photos with Attribution RequirementsnTortoise – by Niccie King – – by Michael Malz – Loris – by David Haring – – by Poorna Kedar – Center – by McGheiver – – by cursedthing –”,

UML, Class Diagram, Tutorial, Unified Modeling Language, Training, Examples, How to, e-learning, Attributes, Methods, Visibility, Inheritence, Relationships,…

Leave a Comment