In: Computer Science
Given the following specification, design a class diagram using PlantUML. To design the class diagram, use abstract, static, package, namespace, association, and generalization on PlantUML
Specification:
Answer:
The code to generate required class diagram on PlantUML
@startuml
School "1" -down-> "1" Members.Principal
School "1" -down-> "N" Members.Student
School "1" -down-> "N" Members.Teacher
School "1" -down-> "N" Infrastructure.PlayGround
School "1" -down-> "N" Infrastructure.Room
package Members {
abstract class Person {
name
birthDate
}
class Teacher {
salary
}
class Principal {
salary
}
class Student
Person <|-- Teacher
Person <|-- Student
Person <|-- Principal
Person "1" - "N" Infrastructure.Books : borrow
}
package Infrastructure {
class Books {
title
abstract
isAvailable()
borrow()
return()
}
Playground "1" - "N" Swing : has
Room "1" -left-> "N" Chair : has
Room "1" -right-> "N" Door : has
Room <|-- office
Room <|-- RestRoom
Room <|-- ClassRoom
Room <|-- Cafeteria
ClassRoom "1" -left-> "N" Computer : has
ClassRoom "1" -right-> "N" Desk : has
Desk "1" -down-> "N" Ruler : has
}
The Class diagram describes the attributes and also operations of a class and constraints inflict on the system.
The class diagrams are extensively used in the modeling because they are the only UML diagrams, which can be mapped directly with object-oriented languages.
Given,
specifications into two broader categories.
Defining
both members of school and infrastructure of school.
We have defined these broader classification as different packages.
Members and Infrastructure
Given, 3
types of person : Principal, Teachers, Many Students
Each person class have name and birthdate. These holds true for all
three specific types hence these are properties of
superclass.
The Teacher and Principal have specific attribute ----
salary.
Person can borrow books. (1 person can borrow many books and a
single book is borrowed under name of single person at a time hence
1:N association exists here)
Infrastructure Consists of: Books
( Each of these persons has a
name, birth date, and may borrow and return
books)
Have attributes title and abstract ,Desk can have many
rulers (1:N association)
Methods – is Available that checks whether book is available at
that point of time
borrow() and return() to perform borrow and return operation on
book.
Play Ground (1 playground can have many swings depicts a 1 to many
association)
Room (1 room can have many doors and desks 1:N association)
Rooms can be of 4 types : Office, Restroom, Class Room,