Skip to content

This textbook is in beta – content is actively being refined. Report issues or suggestions

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

Studentname: stringstudent_id: stringgrades: list__init__(name, student_id)add_grade(grade: float)get_average(): floatget_info(): string

Showing relationships between classes

Schoolname: stringaddress: string__init__(name, address)enroll_student(student: Student)add_course(course: Course)Studentname: stringstudent_id: stringgrades: list__init__(name, student_id)add_grade(grade: float)get_average(): floatCoursecourse_name: stringcourse_code: stringteacher: Teacher__init__(name, code, teacher)enroll_student(student: Student)get_enrolled_count(): intTeachername: stringemployee_id: stringsubject: string__init__(name, id, subject)teach_course(course: Course)enrollsofferstaught byenrolled in

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

Vehiclemake: stringmodel: stringspeed: float__init__(make, model)start(): booleanstop(): booleanaccelerate(): voidCardoors: intfuel_level: float__init__(make, model, doors)accelerate(): voidrefuel(amount: float): voidMotorcycleengine_size: inthas_sidecar: boolean__init__(make, model, engine_size)accelerate(): voidwheelie(): booleanElectricCarbattery_level: floatcharging_port: string__init__(make, model, doors, battery_capacity)charge(duration: int): voidget_range(): float

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

Process Student EnrollmentValidate Student DataCheck PrerequisitesUpdate DatabaseSend Confirmationvalidation resulteligibility statusstudent recordenrollment details

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

StudentTeacher1ProcessEnrollment2ValidatePrerequisites3UpdateRecordsStudent DatabaseCourse Databaseenrollment requeststudent detailsprerequisite checkcourse requirementsvalidation resultupdated enrollmentconfirmationapproval

DFD levels

Level 0 (Context Diagram): Shows the system as a single process with external entities

StudentTeacherAdministratorLibraryManagementSystemborrow requestbook + due datebook recommendationavailability statusnew book detailsinventory report

Level 1: Breaks down the main system into major processes

StudentTeacher1ManageBorrowing2ManageInventory3GenerateReportsBook DatabaseUser Databaseborrow requestborrowed bookbook querybook detailsbook recommendationnew bookbook datauser data

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:

Customercustomer_id: stringname: stringemail: stringplace_order(cart: ShoppingCart)view_order_history()ShoppingCartitems: listtotal: floatadd_item(product: Product)remove_item(product: Product)calculate_total(): floatProductproduct_id: stringname: stringprice: floatstock_quantity: intupdate_stock(quantity: int)Orderorder_id: stringdate: datetimestatus: stringtotal_amount: floatprocess_payment()ship_order()placeshascontainsincludes

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:

CustomerPayment Gateway1ProcessOrder2UpdateInventory3GenerateInvoiceProduct DatabaseOrder Databaseorder detailsproduct requestproduct infoordered itemsstock updateorder recordorder summaryinvoicepayment requestpayment confirmation

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

Useruser_id: stringusername: stringemail: stringpassword: string__init__(username, email, password)create_post(title, content): Postadd_comment(post: Post, content): Commentlogin(email, password): booleanPostpost_id: stringtitle: stringcontent: stringdate_created: datetimeauthor: User__init__(title, content, author)add_comment(comment: Comment)edit_content(new_content)assign_category(category: Category)Commentcomment_id: stringcontent: stringdate_created: datetimeauthor: User__init__(content, author, post)edit_content(new_content)Categorycategory_id: stringname: stringdescription: string__init__(name, description)add_post(post: Post)createswriteshascontains

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

CustomerBank System1ValidatePIN2ProcessWithdrawal3ProcessDeposit4CheckBalance5LogTransactionAccount DatabaseTransaction Logcard + PINvalidation resultaccount lookupaccount detailswithdrawal requestcash + receiptbalance checkcurrent balancebalance updatetransaction detailsdeposit amountdeposit receiptbalance updatetransaction detailsbalance inquirybalance displaybalance requestaccount balancetransaction recordaudit trail

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.