COP 3330 Notes 413 Todays Topics UML Class












- Slides: 12

COP 3330 Notes 4/13

Today’s Topics • UML Class Diagrams

UML Class Diagrams • UML stands for Unified Modeling Language • There are many types of diagrams specified by UML, but we'll only focus on class diagrams • UML class diagrams depict structural relationships among classes

UML Class Diagrams • A class is represented as a rectangle subdivided into three areas • Example: Simplified Student class

UML Class Diagrams • A field is specified with its access modifier first, then its name, then a : , then the type – e. g. on the previous slide, the Java code equivalent of the field would be private double gpa;

UML Class Diagrams • A method is specified with access modifier first, then its name, then its formal parameters in parentheses, then a : , then its return type – e. g. the Java code equivalent of the method header would be public void set. GPA(double newgpa)

UML Class Diagrams • Access modifiers: The visibility of fields and methods are represented by the first character before their names – Private: – Public: + – Protected: #

UML Class Diagrams • Other modifiers: – If a method or field is underlined that indicates that it is static – If a method, field, or class name is italicized, that indicates that it is abstract

UML Class Diagrams • Relationships among classes – Generalization (extends in Java) – Realization (implements in Java) • Arrow with dashed line allows details of the interface to be specified • Lollipop does not

UML Class Diagrams • Relationships among classes – Aggregation: One type of has-a relationship • Indicates weak life-cycle dependence • e. g. an Academic. Department can be destroyed, yet its Students live on – Composition: Another type of has-a relationship • Indicates strong life-cycle dependence • e. g. When a car is destroyed, so is its engine

UML Class Diagrams • Relationships among classes – Pretty much any other relationship is association

UML Class Diagrams • Example: Extremely simplified class diagram of Assignment 3 (fields and methods omitted for clarity)