Sunday, 4 June 2023

PlantUML: Add methods, fields to a class in class diagram

Using the symbol : followed by the field’s or method’s name we can define methods, fields.

 

defineFieldsMethods.txt

@startuml

class Object
Object : Object clone()
Object : boolean equals(Object obj)

interface List
List : add(E e)
List : add(int index, E element)
List : clear()
List : Object[] toArray()

class ArrayList
ArrayList : {static} Long MAX_LIST_SIZE = 1234567

List <|-- ArrayList
Object <|-- ArrayList

@enduml

 

Above snippet generate below diagram.

 

 


There is another better way for the programmers to define fields, methods.

 

defineFieldsMethods2.txt

@startuml

class Object {
	Object clone()
	boolean equals(Object obj)
}

interface List{
	void add(E e)
	void add(int index, E element)
	void clear()
	Object[] toArray()
}

class ArrayList{
	MAX_LIST_SIZE : {static} Long = 1234567
}

List <|-- ArrayList
Object <|-- ArrayList

@enduml

Above snippet generate below diagram.





 

Previous                                                    Next                                                    Home

No comments:

Post a Comment