Vivodo
Vivodo

Reputation: 1564

How to generate UML package diagram with nested packages which may contain same names in different level?

I want to generate a package diagram with hierarchical packages which may contain duplicated names but not in the same level. e.g.:

@startuml
package A {
    package B {
        package C
    }
    package A
}
@enduml

I think, package A.A might be acceptable. But plantuml failed with this error: Thie element (A) is already defined.

I also try the following:

@startuml
folder A {
    folder B {
        folder C
    }
    folder A
}
@enduml

Then, plantuml failed with the same error.

Upvotes: 3

Views: 5614

Answers (3)

hassan khan
hassan khan

Reputation: 1

@startuml

package "Hotel Management System" {
    
    package "Business Logic" {
        class Booking {
            +createBooking()
            +cancelBooking()
        }

        class Customer {
            +registerCustomer()
            +updateCustomer()
        }

        class Room {
            +checkAvailability()
            +bookRoom()
        }

        class Payment {
            +processPayment()
            +issueRefund()
        }
    }

    package "Data Access" {
        class BookingRepository {
            +saveBooking()
            +deleteBooking()
        }

        class CustomerRepository {
            +saveCustomer()
            +deleteCustomer()
        }

        class RoomRepository {
            +saveRoom()
            +deleteRoom()
        }
    }

    package "User Interface" {
        class BookingView {
            +displayBookingForm()
        }

        class CustomerView {
            +displayCustomerForm()
        }

        class RoomView {
            +displayRoomDetails()
        }

        class PaymentView {
            +displayPaymentForm()
        }
    }

    package "Notifications" {
        class EmailService {
            +sendConfirmationEmail()
        }

        class SMSService {
            +sendSMSNotification()
        }
    }

    ' Relationships
    Booking --> BookingRepository : uses
    Customer --> CustomerRepository : uses
    Room --> RoomRepository : uses
    Payment --> Booking : processes
    BookingView --> Booking : interacts with
    CustomerView --> Customer : interacts with
    RoomView --> Room : interacts with
    PaymentView --> Payment : interacts with
    Booking --> EmailService : notifies
    Booking --> SMSService : notifies

}

@enduml

Upvotes: 0

Nikhil
Nikhil

Reputation: 1049

One of the options :

@startuml
package A as pkg0{
    package B as pkg1{
    }
    package A as pkg2{
        package A as pkg3{
        }
    }
    package A as pkg4{
    }
}
@enduml

will give result

enter image description here

Upvotes: 8

JRI
JRI

Reputation: 1942

You can draw diagrams with duplicated names if you include non-printing characters in the definition, e.g. by putting the name in quotes and including one or more space characters:

@startuml
package A {
    package B {
        package C
    }
    package "A "
    package "A  "
}
@enduml

The additional spaces do not affect the layout in the diagram:

UML class diagram with duplicated packages

Upvotes: 3

Related Questions