Skip to content

Latest commit

 

History

History
149 lines (53 loc) · 3.04 KB

1-monday.md

File metadata and controls

149 lines (53 loc) · 3.04 KB

Design: Activity Diagram, Control Flow, Switch

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

Class diagram explanation

Methods are also called operation or behaviour.

Class diagram made in visual Paradigm

CleanShot 2021-09-29 at 07.53.38@2x

Attributes

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

Methods are sometime called behaviour or operation.

Add the parameters of the method. After the : write the type the method returns

Relations - arrows

There are some different relations between classes that we should talk about

Relationships between classes

Inheritance

Use Inheritance when you want to show that one class inherits from another one. Forms a is-a relationship.

Association

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

Composition

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

Aggregation

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.

Multiplicity/cardinality

multiplicities

Real world example

Class diagram example

Exercises

Exercise 1

Exercise 1

Exercise 2

Create the Java code for this diagram

Class diagram exercise 2

Exercise 3

Create the code for this diagram

https://cdn-images-1.medium.com/max/1600/1*TYRSuON0vVxy8olllrBVEw.png

Exercise 4

https://kea-fronter.itslearning.com/LearningToolElement/ViewLearningToolElement.aspx?LearningToolElementId=858632