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
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
- 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
- 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
- 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 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
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()- Set the precondition and inputAssume 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.
- Identify the responsibilitiesThe 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.
- Trace the actionA new object starts with checked_out set to False. The method therefore changes it to True and returns the success message.
- State the expected outputThe 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.
Worked example
Example 2: Specify a queue ADT
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- State the operation rulesEnqueue 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.
- Apply the operations in orderStart with an empty queue. After enqueueing A and then B, A is at the front and B follows it.
- Trace the removalDequeue removes the front item, so it returns A. B remains in the queue.
- Keep storage separateThe result follows from the queue’s first-in, first-out rule. The ADT model does not need to name how the items are stored.
Worked example
Example 3: Organize a small library program
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"- Set assumptions and inputAssume the Library already holds Book objects, each with a title and checked-out status. The input is the title to look up.
- Assign responsibilitiesBook 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.
- Trace the requestFor 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.
- Check that the model agreesThe 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.
Common mistakes and how to avoid them
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
- A named file that groups related Python definitions
- A description of permitted operations and their expected behaviour
- A list of every variable used by a program
- A particular method for storing all program data
Show answer and explanation
Question 2
- The Book object, because it stores its own title
- The Library class, because it manages the collection
- The program module, because it receives the user’s request
- The queue ADT, because books can be waiting
Show answer and explanation
Question 3
- M, because it was added first
- N, because it was added last
- Both items at once
- Neither; an ADT cannot specify removal order
Show answer and explanation
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.