Tuesday, 22 August 2023

How to Define Association Classes in PlantUML

Association class is part of an association relationship between two other classes.

 

Example

(Person, Address) .. PersonAddress

 

associationClass.txt

@startuml

class Person{
	int id
	String name
}

class Address{
	int id
	String country
	String state
	String city
	String pin
}

class PersonAddress{
	int personId
	int addressId
}

Person "0..*" - "1..*" Address
(Person, Address) .. PersonAddress

@enduml

 

Above snippet generate below diagram.

 

 


You can define the association in another direction using below statement (two dashes between classes).

 

Person "0..*" -- "1..*" Address

 

associationClass2.txt

@startuml
class Person{
	int id
	String name
}

class Address{
	int id
	String country
	String state
	String city
	String pin
}

class PersonAddress{
	int personId
	int addressId
}

Person "0..*" -- "1..*" Address
(Person, Address) .. PersonAddress
@enduml

Above snippet generate below diagram.



 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment