Abstract Data Types

ADT examples from CSC108H/A08H

Stack ADT

Object Oriented Programming: A reminder

A class is responsible for maintaining the consistent state of the instance variables. To do this, we have 'public' methods (functions that operate on instances) that are supposed to take an instance from one consistent state to another. A class captures

Example

A Balloon IS-A: (later) HAS-A: amount - the amount of air in the Balloon capacity - the maximum amount of air the Balloon can hold popped - True/False (whether this Balloon is popped or not) RESPONDS-TO: __init__ - the constructor, when we create a new Balloon inflate(amount) - add amount to self if self is not popped, possibly popping self deflate(amount) - remove amount from self if self is not popped __str__ - obtain a string representation of self Note: By consistent state in this case, we mean, at all times 0<=self.amount<=self.capacity Balloon.py is our start at implementing the class Balloon.

Implementing a Stack using classes in Python

Queue ADT