Class diagrams Terézia Mézešová. Class diagram static diagram, part of UML describing classes...

Preview:

Citation preview

Class diagrams

Terézia Mézešová

Class diagram

• static diagram, part of UML describing classes structure of system

• shows classes, their attributes and methods and relationships between classes

• classes represent main interactions in system and classes to be programmed

Classes

• name• attributes• methods

• abstract classes have name in italics

Attribute and method syntax

• visibility name : data_type• visibility name ( parameter_name : parameter_type, ... )

• visibility:• + public• - private• # protected• / derived• _ static

Relationships

class level:1. generalization2. realization

instance level:3. association4. aggregation5. composition

Generalization

• "is a" relationship, inheritance• instance of subtype is also instance of superclass

Realization

• one element realizes the behavior of second element• e.g. relationship between classes and interfaces showing that the

class realizes methods offered by the interface

Association

• represents static relationship between objects of two classes

Aggregation

• "has a" relationship• type of association relationship• can only involve two classes

Composition

• "owns a" relationship• stronger than aggregation• if the container class is destroyed, all contained classes must be

destroyed as well

Other types of relationships

• dependency - one class uses another at some point

• multiplicity:1. 0..1 - no or one instance2. 1 - exactly one instance3. 0..* - zero or more instances4. 1..* - at least one or more instances

Thank you for your attention

Recommended