This video is super good: https://www.youtube.com/watch?v=UI6lqHOVHic&t=478s
A class diagram is a way to visualize your classes. It can be very helpful to get an overview of the code that has been created. especially thinking about how different classes interact with each other.
Class diagram made in IntelliJ
Methods are also called operation or behaviour.
Class diagram made in visual Paradigm
Attributes are also called fields
Attributes are written above the seperating line.
The plus sign means public
The minus sign mean private
What you write after the :
should be the type
Methods are sometime called behaviour or operation.
Add the parameters of the method. After the :
write the type the method returns
There are some different relations between classes that we should talk about
Use Inheritance when you want to show that one class inherits from another one. Forms a is-a relationship.
Indicates that there is a connection between two classes.
class Food {
public String name;
public Ketchup ketchupCondiment;
}
Here a class with another class as attribute. That is what is understood by association
When a child object cannot exist without its parent object. A finger cannot exist without the hand. Or a hand is composed of fingers.
A human needs a heart to live and a heart needs a human body to function on. In other words when the classes (entities) are dependent on each other and their life span are same (if one dies then another one too) then its a composition.
A visitor centeres bathroom does not exist if the visitor center gets destroyed
The best way to understand this relationship is to call it a “has a” or “is part of” relationship. For example, consider the two classes: Wallet and Money. A wallet “has” money. But money doesn’t neccessarily need to have a wallet so it’s a one directional relationship.
Another example is books and bookstores. A book can exists without being in a bookstore.
Create the Java code for this diagram
Create the code for this diagram