PlantUML with VS Code - creating a Classes Diagram (Part 2)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi there hi there this is the techie maki channel uh in the last video we were talking about how to design an order taking system and then we started to think about what would be the components right the high-level components that would be part of the solution we ended up getting customer orders menu and payments and now we're gonna go even further and start to think about what is the data model that we need uh what are the entities that we need as part of these big components right in order to serve orders for customers and receive payments okay so uh the first thing we're going to do is we're going to create a new file it's going to be called classes dot p u m l and here in this file we're gonna define the same thing using client uml so you start uml and end uml and here we're going to define again a name order taken classes great now let's think about from a data structure perspective it's different from actually thinking about components it's a good exercise for you to think of how the persistence also is going to be right and what are the main functions right the main methods that your solution is going to have so the first thing that we are going to think about is the order class right so let's think about the order and at this moment you're going to see that i didn't put that on the plural i've i've put that in singular because we're thinking about the order entity okay so the first information that we have about an order is definitely order id right uh the other id of this order and let's define it right actually a give it is a very interesting type of structure because basically you can uh interchange and then you can you can share this unique identification between different services we're gonna see that as we move along with services mindset and then you can guarantee uniqueness right so that's a good way for you to share that same order id between different systems and services and you can still keep the integrity of course that it's possible to have collisions but this is something that we're not going to cover in this video so then second thing about an order is of course how much you pay right so you need to think about the total amount of your order and let's put it as a decimal right as we as we do this here we can see automatically the plain uml preview changing as we go so the third thing that is important about an order is how much you pay in terms of taxes right you need to pay taxes for every order that you actually take many countries they really expose the tax uh together with your receipt so it's important to actually have that information linked to it so basically is your total tax so let's use as well as a decimal because we're talking about money now thinking about the order uh we're gonna have a total amount and a total tax of something usually when you are in a restaurant or in an e-commerce platform your order is not composed by a single product it is usually composed by one or more products one or more items on the menu for example so in that case we need to define a structure that allow us to define items inside of an order so let's define this structure we're going to call it order items so order items is going to be a list of order items so this structure is actually a new one if you think about the components right we were defining the high level components of the system and we were not in getting into the detail of the entities and this is an entity that is part of the orders component but basically it's a specific structure a specific entity because we need to actually persist that data and we need to keep that structure when we talk about orders this is a common characteristic of an order right so let's define this class so order item order item class and what are the type of data that we're going to have in an order the first thing is definitely the order order item id right we need to define a unique identification for this ordered item id so now let's think about what is inside the order item it is the price we need to define the price of that and as it's something related to money we need to define that the type is actually decimal this item is of a certain type and the type is actually defined in the menu and we are gonna get there but even before that usually when you are let's say that you're buying one book you may choose to buy not only one book right you may buy two of the same book so in this case you are going to define what is the quantity of that order item and it's an integer so okay so these are the basic things that you define let's see what else right i think also oh that's a very important one we need to define as well what is the text for the individual item it's a very common way of order taking domain to call the price of one specific item as unit price and then other than this we can define the total text right we can say total text and it's going to be decimal as well and we can say unit text so what is the text that is on top of that specific unit but hold on in this case we are defining a lot of properties but i understand that some or the majority of these properties here they are not like a raw data some of them are generated via calculation so for example total amount right total amount is the sum of prices of all the items inside of an order of course that we can also define that as properties that are not like they do not have a setter they only have a getter and so they return a calculated value that's also okay i just wanted to make it clear here inside of this class diagram that these data are actually calculated okay so in order to do that one way to do is to change that instead of being a property definition it can be a method definition so we can say decimal total amount and then that's it right so then we can even remove that and if you look at the diagram here you're going to see that it now will show up after we put the parenthesis you can see that it goes to another section that is the method section so total amount is going to be calculated and it's actually in the method section let's say the same thing right we also want to calculate the total tax that is pretty much the sum of all the total taxes of all the items inside of an order as well it's going to be a method same thing for the order item we have like the total price and we have the total tax so these two information can be transformed into uh two methods so let's do the same thing so decimal total tax and let's do decimal total price so that's that simplifies a little bit that makes the class visualization a little bit more interesting in terms of what are really the data that we need is stored and what are the data that we're going to calculate okay so great so in this case we are just talking about the orders component but there is much more right we haven't yet started to establish some relationship and here is where there's actually a very good way to express relationships in the class diagram when you think about uml so for example if you want to establish a relationship that is really a direct relationship so for example there is no point in having order item if you don't have an order because it's really interwined it's really like one thing cannot live without the other and in this case is what we use to establish this relationship or to actually make it visible in the class diagram is by using composition thinking so we link with a certain visual reference here that is called composition okay so let's do that for the order and order item i'm going to actually call order and then order has composition this is the asterisk means composition and then we're going to put order item over here and that's the way that it does to establish this relationship so this symbol over here is the composition so this is how you define this composition it's also interesting to to inform that this relationship is one too many right so you have one order and then you have many other items so usually you do that by creating like double quotes here double quotes to open double codes to close and then you put inside of it what is the relationship it's a one to n relationship okay okay so now we've finished the order structure so let's think about the menu component and what are the entities that menu actually has right the first very important component that menu has is the product the product is basically the structure that defines all the items in a menu so we can call it product class and this product class contains all the the menu all the catalog of items that are available for the customer to request right so the customer goes to a restaurant for example and then he sees over there we have like this three four five different types of sandwiches and also different types of soda he can pick and choose each of them add these items to the order pay at the counter either take it home or eat in in the restaurant in this video we are actually designing what is like a very common order taken type of structure but in real scenarios right when you are designing a system you need to engage the product owner and the specialists during the whole process you need to understand and capture what are the names that they use what is the common language that is actually clear for everybody so getting back to our use case here let's continue with the product so the product has a product id and it also has what is the product name right we need to define a name for the product it's going to be a string so other than this we need to define for example what is the price of that product so let's define that as the price and the price is basically a decimal as well so here is the question why are we defining the unit price over here if we are also defining that over here when you think about designing components that have some sort of independence it may be a good practice to separate even duplicate information in two different places so the same information would be okay to be stored in two different entities for now let's leave it this way because i'm going to actually show how this is going to be beneficial for us in the future so continuing here i'm going to define the price and what else let's think about the text as well and finally we're going to define the image path right so it's the path actually to an image that's going to be stored in the server and that we're going to use to know exactly on our system uh what is the image to display for that specific product so now let's go to the relationship what is the relationship between the order and the order item in the product so in this case there is a very clear relationship between the order item and the product which we're going to first define in the order item structure so we need to define what is the product id for that specific order item and this kind of establishes the basic relationship now we are going to define also as well and let me just make it a little okay that's great let's make it a little bigger okay that's fine so then uh we actually have a relationship between the order item and the product but we haven't been able to define that here uh yet right and this is not like a composition relationship so what is it when you think about relationships that are not like a composition you are because for example if you have 10 products and you haven't applied them to any order item that's okay that's not a problem right the product can leave without the order items it's just a relationship between these two entities when we talk about this type of relationship it's actually an aggregate so finally let's add the order item here and use lowercase o to define the aggregate okay so now let's continue the definition right we're going to define now the payment class the payment class basically will contain the payment id we also need to define what is the payment status the payment status is actually going to be an enumerable so let's say nm payment status okay in the payment status we're going to define for example in progress paid so on and so forth we also need to define what is the payments type which is also an enum the payment type can be for example a credit card payment can be cash we also need to define the latest update of the payment also we need to define what is the amount that was paid here we're not going to record any user data in regards to payment we're not going to record like credit card information or anything related to the credit card but we need to define an important information when we talk about the payment class right and what is it we need to define the action pay and inside of the action pay yes we need to define the basic data so we have like the name name on card we have for example credit card number right we have also uh the security code and finally we have the expiration date okay so basically this is all for payment let's think about now that we also need when we talk about payment we definitely need an information about what is the order right so what is the what is the order related to that specific payment and when we do that it's also important to define another aggregate let's go for payment and then we go on the payment all lowercase and establish a relationship with order okay so this is going to reflect uh soon in the diagram so let's define now the customer class so for the customer what we have is we have the customer id we need to know the name of the customer the address and here is a very interesting situation when we talk about the address address actually is a complex type it contains street information it contains the number of the house it contains also many other information that are relevant and that makes sense to be defined as a specific class so let's define this specific address class okay class address this street line one right and also this street line two zip code zip code is also gonna be a specific complex object we also need to define city city is going to be an enum and finally state let's define the zip class it contains a code so now let's define as well the innumerables for the city and the enumerables for state all of these new classes have brought many relationships that we haven't yet defined it so let's define these relationships here so for customer there is a relationship between order and the customer it's again an aggregate relationship it's also important to go back to the order and define that right because we need to have the customer here customer id needs to be part of the order object because that's the way that we link the order and the customer let's continue then to define some relationships there are missing associations from this diagram so one of the associations that we are missing here is the one between customer and address this relationship is a composition relationship because you cannot have an address without a customer continuing on the same thread there is a relationship between the address and city address and zip address and state we also have a relationship with payment that are not listed here so payment also has another composition relationship with payment type and finally payment with payment status all right so we have just finished the creation of the first version of our class diagram of course that this is going to pass through many many iterations and as soon as we learn more and more about the system this is going to evolve dramatically right but this is a very good thing to have in order to be able to start your development because then you have the visualization the initial understanding of the entities of your solution in the next video we're going to create a first sequence diagram and we're going to see the relationship between all of these entities and especially all of these components if you want me to design and implement another use case just put on the comments below don't forget to subscribe and also to click all the notification buttons in order to be notified when a new video is published thanks a lot for joining and see you soon on the next video [Music]
Info
Channel: TechyMaki
Views: 11,657
Rating: undefined out of 5
Keywords: PlantUML, Visual Studio Code, VSCode, System Design, agile design, agile documentation, UML, Daniel Makiyama, visual code, visual code studio, plantuml online
Id: wNM9M4gB6uY
Channel Id: undefined
Length: 19min 19sec (1159 seconds)
Published: Thu Nov 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.