DoAssignment study guide

C1.1 · Model modules, classes and abstract data types

Learn to model modules, classes and abstract data types through clear examples and targeted practice.

Ontario Grade 12 Computer Science

Designing Modular Programs

Ontario ICS4U study lesson for expectation C1.1

This lesson addresses Ontario Grade 12 Computer Science expectation C1.1: “Model modules, classes and abstract data types.” It builds on ICS3U experience with variables, functions and program structures. A model helps clarify a program’s organization and responsibilities. A module groups related program elements; a class describes a kind of object and its responsibilities; an abstract data type (ADT) describes permitted operations and what they do. These models can work together, but they answer different questions.

What you will learn

  • Explain how modules, classes and abstract data types model different aspects of a program.
  • Represent class responsibilities using attributes and methods.
  • Describe an abstract data type through its permitted operations and expected behaviour.
  • Model how related modules and classes divide responsibilities.

1. Choose the model that answers the question

Begin by asking what you need to make clear. A module answers, “Which related code belongs together?” A class answers, “What kind of object is represented, and what information and actions belong to it?” An ADT answers, “Which operations can a user request, and what should each operation do?” Keeping these questions separate makes a program model easier to read.
A module is a named unit of program organization. Its exact meaning depends on the language and its conventions. In Python, one common convention is a file containing related definitions, such as functions and classes. This illustrates one language’s approach; the broader model is about grouping related program elements.
A class describes objects with associated information and actions. Attributes represent information associated with an object; methods represent actions or services associated with it. Objects created from one class can have different attribute values. A class model should identify a useful responsibility rather than simply gather nearby code.
An ADT describes a type through its values, permitted operations and expected operation behaviour, without specifying a particular way to store the data. A queue, for example, allows items to be added at the back and removed from the front. Its first-in, first-out rule is part of the model; the storage choice is not.
  • Module: groups related program elements.
  • Class: describes objects, their information and their actions.
  • ADT: specifies permitted operations and expected behaviour, independently of storage details.

2. Model a class through information and actions

To model a class, name the kind of object and choose attributes that describe it. Then identify methods that express actions or services belonging to that object. A compact model is often more useful than one that attempts to represent every possible detail.
Consider a library book. A small model might record its title and whether it is checked out. A borrow method can change that status when borrowing is allowed. In this model, the precondition for a successful borrow is that the book is available. Stating the precondition distinguishes the successful case from an unsuccessful request.
In the Python 3 example, the constructor input is a title, and a new book starts with checked_out set to False. The borrow method has no separate input; it uses the book’s current status. If the book is already checked out, it returns an unavailable message and leaves the status unchanged. Otherwise, it changes the status and returns a success message.
Trace the object’s state rather than assuming the method’s result. For a new book titled River Road, checked_out begins as False. A borrow request changes it to True and returns Borrowed: River Road. This is an expected result derived by reading the code, not a claim that the code was run.
  • Attributes describe an object’s information.
  • Methods describe actions or services associated with the object.
  • Trace attribute values before and after an action to check that the model is clear.

3. Describe ADTs through their operation rules

An ADT description focuses on what a user can request and what result to expect. For a queue, enqueue adds an item at the back; dequeue removes and returns the item at the front. The queue follows first-in, first-out behaviour: the earliest item still waiting is the next one removed.
An operation description should also state what happens in relevant boundary cases. If dequeue is requested when the queue is empty, no front item exists to return. The ADT model must specify how that case is reported or handled. That choice belongs in the specification.
The queue rules do not require a particular storage structure. A class might implement the queue operations using a storage choice, but a user of the ADT should be able to rely on the stated operation behaviour. The ADT and its implementation are related but not identical: one specifies expected behaviour, while the other provides it.
Trace a small case by applying the rules in order. Starting with an empty queue, enqueue A and then enqueue B. A is at the front, followed by B. One dequeue returns A and leaves B waiting. This result follows from the ADT’s operation rules, not from a claim about how the items are stored.
  • Specify operation inputs, results and expected behaviour.
  • A queue removes the earliest item that is still waiting.
  • State the expected result for an operation such as dequeue on an empty queue.

4. Combine modules and classes in one model

A program model can show both organization and responsibilities. In a small library program, a Book class can represent one book, while a Library class manages a collection of books. A library module could group those related class definitions. A separate program module could handle a user request and present a response. The model should show connections that represent real use or responsibility.
State assumptions before tracing an example. Suppose each Book object has a title and a checked-out status, and the Library object manages a collection of Book objects. A title is supplied as the lookup input. Library searches its collection and returns a matching Book object, or a not-found result if no title matches. The availability response depends on the matching book’s status.
This division gives each part a clear role: Book models one book and its status; Library manages the collection and provides lookup; the program handles the request and response. The module groups related definitions, while the classes describe objects and responsibilities. The model is useful when its labels, relationships and expected results agree.
When reviewing your own model, check which question each part answers. If you are describing a grouping of definitions, you are modelling a module. If you are describing an object’s information and actions, you are modelling a class. If you are describing permitted operations and their behaviour without a storage choice, you are modelling an ADT.
  • A module can group related classes; a program part can use their services.
  • Assign a method to the class whose responsibility it supports.
  • Make assumptions and expected outcomes explicit when tracing a model.

Worked example

Example 1: Model a book as a class

Model a book that records its title and whether it is checked out. Trace an attempt to borrow an available book titled River Road.
Book class model
hashasprovidesAttribute: titleAttribute: checked_outBook classMethod: borrow

The class connects its two attributes and borrowing method as one responsibility.

Python 3

class Book:
    def __init__(self, title):
        self.title = title
        self.checked_out = False

    def borrow(self):
        if self.checked_out:
            return "Unavailable"
        self.checked_out = True
        return "Borrowed: " + self.title

book = Book("River Road")
message = book.borrow()
  1. Set the precondition and input
    Assume the book is available before the request. The constructor input is the title River Road; the borrow action uses the resulting Book object’s current status.
  2. Identify the responsibilities
    The title and checked_out attributes describe the book. The borrow method changes that book’s status, so the method belongs with the Book responsibility in this model.
  3. Trace the action
    A new object starts with checked_out set to False. The method therefore changes it to True and returns the success message.
  4. State the expected output
    The expected returned message is Borrowed: River Road, and the object’s checked_out value becomes True. This is a code trace, not a report of execution.
Answer: The Book class groups the title and checkout status with the borrow action. Given an available book titled River Road, the trace predicts a successful message and a checked-out status.
Check: If checked_out is already True, the method returns Unavailable and leaves that status unchanged.

Worked example

Example 2: Specify a queue ADT

Describe a queue’s operations and expected behaviour without choosing a storage method. Trace adding A, adding B, then removing one item.
Queue ADT and implementation relationship
provides specified behavQueue ADT: permitted opeQueue implementation: pr

An implementation provides the behaviour specified by the ADT.

Pseudocode

ADT Queue
    enqueue(item): add item at the back
    dequeue():
        if empty, use the specified empty-queue result
        otherwise, remove and return the front item
  1. State the operation rules
    Enqueue takes one item and adds it at the back. Dequeue takes no item input and removes and returns the front item when the queue is not empty. The ADT description must also specify what happens if dequeue is requested while empty.
  2. Apply the operations in order
    Start with an empty queue. After enqueueing A and then B, A is at the front and B follows it.
  3. Trace the removal
    Dequeue removes the front item, so it returns A. B remains in the queue.
  4. Keep storage separate
    The result follows from the queue’s first-in, first-out rule. The ADT model does not need to name how the items are stored.
Answer: The queue ADT specifies enqueue and dequeue behaviour. In this trace, dequeue returns A and leaves B waiting.
Check: A complete model also states what dequeue reports or does when the queue is empty.

Worked example

Example 3: Organize a small library program

Model modules and classes for a small program that looks up a book title and reports whether the matching book is available.
Library program organization
usesgroupsgroupsmanages objects ofProgram module: handlesLibrary moduleBook class: title and stLibrary class: manages c

The program uses services from a module that groups the Book and Library classes; Library manages Book objects.

Python 3

class Book:
    def __init__(self, title, checked_out):
        self.title = title
        self.checked_out = checked_out

class Library:
    def __init__(self, books):
        self.books = books

    def find_book(self, title):
        for book in self.books:
            if book.title == title:
                return book
        return None

def availability(library, title):
    book = library.find_book(title)
    if book is None:
        return "Not found"
    if book.checked_out:
        return "Checked out"
    return "Available"
  1. Set assumptions and input
    Assume the Library already holds Book objects, each with a title and checked-out status. The input is the title to look up.
  2. Assign responsibilities
    Book represents one book and its status. Library manages the collection and looks up a title. The program module handles the user request and presents the response. In this Python example, a module is represented by a file grouping related definitions and code.
  3. Trace the request
    For the input River Road, Library checks its Book objects in order. If it finds a match whose checked_out value is False, the expected response is Available. If no title matches, the expected response is Not found.
  4. Check that the model agrees
    The diagram shows the program using the library module and the library module grouping Book and Library. The trace follows the responsibilities shown; it is not a claim that the code was executed.
Answer: The library module groups the Book and Library classes. Book models one book; Library manages the collection and provides title lookup; the program module handles the request and response.
Check: Collection lookup belongs to Library in this model. The checked-out status belongs to the matching Book.

Common mistakes and how to avoid them

Treating a module, class and ADT as interchangeable names for a program part.
Correction: A module groups related definitions; a class models objects and responsibilities; an ADT specifies operations and expected behaviour.
Describing a queue ADT by requiring a particular storage structure.
Correction: Describe the operations and their behaviour first. A particular storage choice belongs to an implementation.
Putting every action in one class just because it is convenient.
Correction: Assign actions to the class or module whose responsibility they support, and make that division visible in the model.
Leaving outcomes unclear when an operation cannot be completed.
Correction: State relevant preconditions and expected outcomes, including the empty-queue case or a title that is not found.

Lesson summary

  • Model modules as groups of related program elements.
  • Model classes through objects’ attributes and methods, with clear responsibilities.
  • Model ADTs through permitted operations and their expected behaviour, not a particular storage choice.
  • Check that assumptions, responsibilities, diagrams and traces agree.

Check your understanding

Question 1

Which description best fits an abstract data type?
  1. A named file that groups related Python definitions
  2. A description of permitted operations and their expected behaviour
  3. A list of every variable used by a program
  4. A particular method for storing all program data
Show answer and explanation
A description of permitted operations and their expected behaviour
An ADT describes available operations and what they mean, independently of a particular storage implementation.

Question 2

In the library model, which part is responsible for finding a title in the collection?
  1. The Book object, because it stores its own title
  2. The Library class, because it manages the collection
  3. The program module, because it receives the user’s request
  4. The queue ADT, because books can be waiting
Show answer and explanation
The Library class, because it manages the collection
The model assigns collection management and title lookup to Library. Book represents one book and its status.

Question 3

A queue receives item M and then item N. If neither has been removed, which item does dequeue return first?
  1. M, because it was added first
  2. N, because it was added last
  3. Both items at once
  4. Neither; an ADT cannot specify removal order
Show answer and explanation
M, because it was added first
The queue’s first-in, first-out rule means M is removed before N.

Key terms

Module
A named unit for grouping related program elements; the exact convention depends on the programming language.
Class
A description used to create objects with associated information and actions.
Attribute
Information associated with an object.
Method
An action or service associated with a class or its objects.
Abstract data type (ADT)
A model defined by its permitted operations and expected behaviour, rather than by a particular storage implementation.
Precondition
A condition assumed to be true before an operation is performed.

Continue through ICS4U

View the complete ICS4U Ontario Grade 12 Computer Science curriculum and lessons

Tutor support for C1.1 · Model modules, classes and abstract data types

Working on C1.1 · Model modules, classes and abstract data types in ICS4U? Bring the question and your own attempt. In a live session, you can identify the data and assumptions, choose a suitable representation, and interpret the result in context. Ask about the first step that does not make sense, then try a similar question yourself.

Explore coding tutoring · Request an eligible free 30-minute introduction. Your request is matched by subject and language; a tutor must accept before a time is confirmed.

برای مبحث C1.1 · مدل‌سازی پیمانه، کلاس و نوع داده انتزاعی در درس ICS4U، سؤال و تلاش خود را همراه بیاورید. در جلسه می‌توانید داده‌ها و فرض‌ها را مشخص کنید، نمایش مناسبی برگزینید و نتیجه را در متن مسئله تفسیر کنید. راهنمای معلم برنامه‌نویسی را ببینید یا جلسهٔ معارفهٔ رایگان ۳۰ دقیقه‌ای درخواست کنید. زمان جلسه پس از پذیرش معلم قطعی می‌شود.

About this lesson and its review

Published by DoAssignment. This reviewed lesson follows Ontario Grade 12 Computer Science (ICS4U), expectation C1.1. It is a study resource, not an official curriculum publication.

Before publication, content is checked for structure, mathematical or chemical notation, calculations, course boundaries, and readability. Errors can still occur, so corrections are welcomed.

Official curriculum reference

Report a correction or ask a question