5.5 Modelling with class diagrams, structure charts and DFDs¶
Learning objectives¶
By the end of this section, you will be able to:
-
Create class diagrams to represent object-oriented systems
-
Design structure charts to show hierarchical decomposition of functions
-
Draw data flow diagrams (DFDs) to map data paths through a system
-
Understand how these three modeling techniques complement each other
-
Choose the appropriate diagram type for different aspects of system design
-
Map responsibilities and data flows in a system design
Why we need different modeling techniques¶
When designing software systems, we need different perspectives to understand the complete picture:
-
Class diagrams show the static structure: what objects exist and how they relate
-
Structure charts show functional decomposition: how complex tasks break down into simpler ones
-
Data flow diagrams show data movement: how information flows through the system
Think of it like designing a house - you need floor plans (structure), electrical diagrams (connections), and plumbing diagrams (flow). Each shows a different but essential view.
Class diagrams¶
Class diagrams a diagram to visualize the classes in your system, their attributes, methods, and relationships.
Basic class representation¶
Showing relationships between classes¶
This diagram shows:
-
Composition (filled diamond): School contains Students and Courses
-
Association (line): Courses are taught by Teachers
-
Many-to-many (o{ to }o): Students can enroll in multiple Courses
Inheritance in class diagrams¶
Structure charts¶
Structure charts show how a complex system breaks down into simpler components in a hierarchical way. They’re especially useful for understanding the functional decomposition of a problem.
Basic structure chart example¶
For a simple library management system:
Library Management System
├── User Management
│ ├── Add Member
│ ├── Remove Member
│ └── Update Member Info
├── Book Management
│ ├── Add Book
│ ├── Remove Book
│ └── Search Books
└── Lending Operations
├── Borrow Book
├── Return Book
└── Calculate Fines
Structure chart with data flow¶
When to use structure charts¶
-
Planning the breakdown of complex functions
-
Understanding legacy procedural systems
-
Showing the hierarchy of method calls
-
Documenting system architecture at a high level
Data Flow Diagrams (DFDs)¶
Data Flow Diagrams show how data moves through a system, focusing on the transformation of information rather than the control flow.
DFD symbols and conventions¶
-
Circles/Processes: Transform data (numbered 1, 2, 3…)
-
Rectangles/External entities: Sources or destinations of data
-
Open rectangles/Data stores: Where data is stored
-
Arrows: Data flow with descriptive labels
Simple DFD example¶
DFD levels¶
Level 0 (Context Diagram): Shows the system as a single process with external entities
Level 1: Breaks down the main system into major processes
How the three techniques complement each other¶
Example: Online Shopping System¶
Let’s see how each diagram type provides a different but complementary view:
1. Class Diagram - Shows the static structure:
2. Structure Chart - Shows functional decomposition:
Online Shopping System
├── Customer Management
│ ├── Register Customer
│ ├── Authenticate User
│ └── Update Profile
├── Product Catalog
│ ├── Browse Products
│ ├── Search Products
│ └── View Product Details
├── Shopping Cart
│ ├── Add to Cart
│ ├── Remove from Cart
│ └── Calculate Total
└── Order Processing
├── Process Payment
├── Update Inventory
└── Generate Invoice
3. Data Flow Diagram - Shows data movement:
When to use each diagram¶
| Diagram Type | Best Used For | Answers Questions |
|---|---|---|
| Class Diagram | Static structure, relationships | “What objects exist? How do they relate?” |
| Structure Chart | Functional breakdown, hierarchy | “How does this complex task break down?” |
| Data Flow Diagram | Data movement, transformation | “Where does data come from and go to?” |
Practice¶
Exercise 1: Create a class diagram
Design a class diagram for a simple blog system with:
-
Users who can create posts and comments
-
Posts that belong to users and can have multiple comments
-
Comments that belong to both users and posts
-
Categories that posts can be assigned to
Task: Create a class diagram showing classes, attributes, methods, and relationships.
Sample Solution
Exercise 2: Design a structure chart
Create a structure chart for a student grade management system that:
-
Allows teachers to input grades
-
Calculates student averages
-
Generates progress reports
-
Sends notifications to parents
Task: Design a hierarchical breakdown showing the main system and its sub-functions.
Sample Solution
Student Grade Management System
├── Grade Input Management
│ ├── Validate Teacher Login
│ ├── Select Student
│ ├── Enter Grade Data
│ └── Save Grade Record
├── Grade Calculation
│ ├── Retrieve Student Grades
│ ├── Calculate Subject Average
│ ├── Calculate Overall GPA
│ └── Determine Letter Grade
├── Report Generation
│ ├── Gather Student Data
│ ├── Format Progress Report
│ ├── Generate PDF Report
│ └── Store Report Record
└── Notification System
├── Check Notification Rules
├── Compose Message
├── Send Email to Parents
└── Log Notification Sent
Exercise 3: Create a data flow diagram
Design a Level 1 DFD for a simple ATM system that:
-
Allows customers to check balance, withdraw money, and deposit money
-
Validates PIN numbers
-
Updates account balances
-
Logs all transactions
Task: Create a DFD showing processes, data stores, external entities, and data flows.
Sample Solution
Recap¶
-
Class diagrams visualize static structure using classes, attributes, methods, and relationships
-
Structure charts show hierarchical functional decomposition from complex to simple tasks
-
Data Flow Diagrams map how data moves and transforms through a system
-
Different perspectives are needed: structure (class diagrams), function (structure charts), and data flow (DFDs)
-
Complementary views together provide a complete understanding of system design
-
Choose the right diagram based on what aspect of the system you need to communicate
These modeling techniques are essential tools for system design, helping you visualize different aspects of your software before you start coding. They improve communication with stakeholders and provide a roadmap for implementation.