Chap 7.4 Class Diagram
Chap 7.4 Class Diagram
4 Class Diagram
Basics
• Class diagrams are the most common diagram
found in modeling object- oriented systems.
• A class diagram
– is a diagram showing a collection of classes and
interfaces, along with the collaborations and
relationships among classes and interfaces.
– Used to model the static design view of a system.
• This involves
» Modeling the vocabulary of the system,
» Modeling collaborations, or
» Modeling schemas.
Basics (cont.)
• Class diagrams are important not only for
– visualizing,
– specifying, and
– documenting structural models, but also for
• constructing executable systems through forward and
reverse engineering.
• Class diagrams describe three different
perspectives when designing a system,
• conceptual, specification, and implementation.
• These perspectives become evident as the diagram is
created and help solidify the design.
Basics (cont.)
• A class diagram
– is a pictorial representation of the detailed system design.
• Design experts who understand the rules of modeling and
designing systems design the system's class diagrams.
• Represents the structure of a system.
• Referenced time and again by the developers while implementing
the system.
• How does a class diagram relate to the use case diagrams
– use cases talk about "what are the requirements" of a system.
– the aim of designing classes is to convert this "what" to a "how" for
each requirement.
– each use case is further analyzed and broken up into atomic
components that form the basis for the classes that need to be
designed.
Elements of a class diagram
• Classes are composed of three things:
– a name, attributes, and operations.
Elements of a class diagram(cont.)
• The class name typically has the first alphabet
capitalized. If your class has more than one
words then capitalize all words and join them.
• E.g Student
• List of attributes/variables the syntax is:
– attribute : type = “default value (if any)”
• e.g. studentId:int, studentName:String
• List of methods the syntax is:
• MethodName(List of parameters(if any)):Return type(if any)
• e.g. String getStudentName(int studentId)
Elements of a class diagram(cont.)
• Interface
– is a variation of a class.
– a class provides an encapsulated implementation of
certain business functionality of a system.
– provides only a definition of business functionality of a
system.
• An interface shares the same features as a class
– contains attributes and methods.
– The only difference is that that the methods are only
declared in the interface and will be implemented by
the class implementing the interface.
Elements of a class diagram(cont.)
• Package
– provides the ability to group together classes and/or
interfaces that are either similar in nature or related.
– Grouping these design elements in a package
element provides for better readability of class
diagrams, especially complex class diagrams.
– is represented as a tabbed folder.