Sunday, 18 June 2023

PlantUML: Use separators to define custom ordering of fields and methods

By default, methods and fields are automatically regrouped by PlantUML.

 

defaultOrdering.txt

@startuml

class Employee{
	' public static fields
	+ {static} AtomicInteger TOTAL_EMPLOYEE_COUNT

	'private instance fields
	- Integer id
	- String name
	- Integer age

	' public static methods
	+ {static} List<Employee> list(Employee... emps)

	' public instance methods
	+ Integer getId()
	+ String getName()
	+ Integer getAge()
	+ String aboutMe()
	+ void setId(Integer id)
	+ void setName(String name)
	+ void setAge(Integer age)

	' private instance methods
	- String lowerName()
}

@enduml

 

Above snippet generate below diagram.

 

 


We can use separators to define our own way of ordering fields and method.

 

Following separators are supported.

 

a.   --

b.   ..

c.    ==

d.   __

 

customordering.txt

@startuml

class Employee{
	-- public static fields --
	+ {static} AtomicInteger TOTAL_EMPLOYEE_COUNT

	.. private instance fields ..
	- Integer id
	- String name
	- Integer age

	== public static methods ==
	+ {static} List<Employee> list(Employee... emps)

	__ public instance getter methods __
	+ Integer getId()
	+ String getName()
	+ Integer getAge()

	__ public instance setter methods __
	+ void setId(Integer id)
	+ void setName(String name)
	+ void setAge(Integer age)

	__ public utility methods __
	+ String aboutMe()

	.. private instance methods ..
	- String lowerName()
}

@enduml

 

Above snippet generate below diagram.


 

Previous                                                    Next                                                    Home

No comments:

Post a Comment