Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

UML Diagrams

Give Feedback

00:00 So far, you’ve been learning about inheritance and composition through these little class diagrams that I’ve crafted. While they have served our purpose so far, they’re not an industry standard by any means, and they don’t necessarily convey all the information that we might need.

00:20 The standard method of creating class diagrams is called UML, Unified Modeling Language. UML is used to show class hierarchies in software projects.

00:34 In other words, it describes the relationships between different classes and it supports composition and inheritance. By planning a project before we start coding it, we can ensure that we make smart design decisions like utilizing inheritance and composition, where it fits.

00:55 This is not a course in software architecture, but we will use UML diagrams to design a project later on. UML diagrams might contain plus (+) and minus (-) symbols next to each member of a class.

01:11 These denote public and private accessibility. Python doesn’t formally support this idea of access modifiers, which is why I haven’t really discussed it up until now.

01:24 Everything in Python is basically public, and it’s up to the developer to use the class responsibly. Don’t worry too much about this. For our purposes, we’re just going to mark every member of every class as public with a + symbol. When it comes to UML diagrams in Python specifically, there isn’t really a right or a wrong way of doing things. It’s all about following a convention and then sticking to it.

01:54 You may have also seen a datatype associated with attributes and methods, written after a colon (:). In the case of attributes, this datatype describes the type of the attribute—such as int, str (string), or something custom, through composition.

02:15 A type following a method name indicates the return type of that method.

02:22 Expressing inheritance with UML is fairly straightforward. A white arrow points from the derived class to the base class. We can write extends to make it clear that this is an inheritance relationship.

02:39 extends is another word for inherits from. We can express composition with UML too. To do that, we draw a solid diamond arrow from the composite class to the component class.

02:55 Remember, the composite is made up of one or more components.

03:01 We can write a little number in the composite class to indicate the number of component instances it should have. We can also write a star (*) to indicate that the composite class can contain a variable number of component instances.

03:19 A range, written in parentheses (()), indicates that the composite class can contain a certain range of instances. For example, (1..4) means between 1 and 4, and (1..*) means at least one.

Erikton Konomi on April 25, 2020

Great tutorial so far! Any recommended resources on UML + Python specifically?

Zishi Wu on May 27, 2020

Hi Erikton,

It might be helpful if you were to take a program from an intro to programming or data structures course in popular Object-Oriented Languages like Java or C++ and draw the UML diagram of the classes in that program. For example, a classic exercise is to implement a linked list, for which you need a node class. But if it’s a singly linked list then your node only has a reference to the next node. Whereas if it’s a doubly linked list then your node has a reference to both the next node and to the previous node. So you could start with an abstract base class called BaseNode, and it requires all Node classes that implement it to have at least two class methods: get_next() and get_value(). Then you could have two concrete classes that implement BaseNode, for example SinglyLinkedNode and DoublyLinkedNode.

Austin Cepalia RP Team on May 29, 2020

@Erikton @Zishi That’s a great example Zishi! And, if you’re interested in Linked Lists, you might want to keep an eye on the video courses page over the next few weeks…

Become a Member to join the conversation.