Translating basic UML diagram into code?
Source: https://youtu.be/oOCEAjlBTZw?list=PLdQddgMBv5zHcEN9RrhADq3CBColhY2hl&t=3688
I am learning about UML Class Diagram, and it has something called an
Association Class
- the example being Supplies
here.
Also Supplier
and Product
are both classes that can have 0..N
of each other: A Supplier
class can have 0...N
of Product
class, and vice versa.
I am currently wondering:
* How an Assocation Class
can be translated into code, and how it differs from a normal class?
* How can I translate the 0..N
requirement between Supplier
class and Product
class into code? What does it mean in code? Normally I just have two files each with their own class, and then I can create them in the main file. But it seems that they must somehow depend on each other?1 Reply
You'd normally see that pattern with database tables
In code, it means that:
1. Each Supply instance has a reference to a Supplier and to a Product. As in, it links together a supplier to a product.
2. If you want to be able to find all products that a supplier supplies, then you need to find all of the Supply instances which reference that Supplier. There are various ways to do this
With a database, you'd have 3 tables. To find all products that a supplier supplies, you'd join your supplier into all of the Supply rows which reference that Supplier, then join that into the Product table to find all of the Products which that Supply references