Download presentation
Presentation is loading. Please wait.
Published byChristopher Peters Modified over 9 years ago
1
CS 2511 Fall2014 2014
2
UML Diagram Types 2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○ Sequence Diagrams ○ Use Case Diagrams
3
Class Diagrams Type of static structure diagram Describes: The structure of a system by showing the system’s classes The class attributes The relationships between classes
4
Class Node Layout Class Name Attributes of Class (Data Members) Operations of Class (Member Functions)
5
Example Class Diagram Revisited public class Circle { private double radius; private double area; protected double getArea(); public void setCenter(Point); public Point center; } Circle radius : double area : double center : Point getArea() : double setCenter(Point)
6
Visibility Specifiers To specify the visibility of a class member (both attributes and methods) use the following before the member's name: public: + protected: # private: - package: ~
7
Example Class Diagram Revisited public class Circle { private double radius; private double area; protected double getArea(); public void setCenter(Point); public Point center; } Circle - radius: double - area: double + center: Point # getArea() : double + setCenter(Point)
8
Class Relationships A relationship is a general term covering the specific types of logical connections found on class and object diagrams. We’ll look at the following: Dependency Aggregation Inheritance
9
Dependency A very weak relationship A class depends on another class if it manipulates objects of the other class
10
UML Dependency Shape - var1 : Point + draw(Circle c) Circle - radius: double - area: double + center: Point # getArea() : double + setCenter(Point)
11
Dependency in Code public class Shape { public void draw(Circle c); private Point var1; // Some other variables and methods … } public class Circle { private double radius; private double area; protected double getArea(); public void setCenter(Point); public Point center; } Notice that draw(Circle c) is the only reference to class Circle in Shape, so a weak relationship
12
Aggregation A class aggregates another if its objects contain objects of the other class. The aggregate class (the class with the white diamond touching it) is in some way the “whole,” and the other class in the relationship is somehow “part” of that whole. Mailbox - messages : ArrayList Message *
13
Aggregation in Code public class Mailbox { private ArrayList messages; // Other Variables and Methods Go Here } public class Message { // Variables and Methods Go Here } Note that this is a 1 to many relationship since for every Mailbox there are 0 or more messages stored
14
Inheritance A class inherits from another if it incorporates the behavior of the other class Special Cases of objects of the parent class type (Possibly) capable of exhibiting additional responsibilities
15
UML Inheritance Child + method2() Parent + method1() Note only methods new to Child are listed in Child class (not methods inherited from Parent)
16
Inheritance in Code public class Parent { public void method1(); } public class Child extends Parent { public void method2(); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.