An interesting way to implement an abstract base class

Discussion in 'Python' started by olsongt@verizon.net, Aug 4, 2006.

  1. Guest

    This one made me smile. From:

    http://aima.cs.berkeley.edu/python/utils.html#Queue

    class Queue:
    """Queue is an abstract class/interface. There are three types:
    Stack(): A Last In First Out Queue.
    FIFOQueue(): A First In First Out Queue.
    PriorityQueue(lt): Queue where items are sorted by lt, (default
    <).
    Each type supports the following methods and functions:
    q.append(item) -- add an item to the queue
    q.extend(items) -- equivalent to: for item in items:
    q.append(item)
    q.pop() -- return the top item from the queue
    len(q) -- number of items in q (also q.__len())
    Note that isinstance(Stack(), Queue) is false, because we implement
    stacks
    as lists. If Python ever gets interfaces, Queue will be an
    interface."""

    def __init__(self):
    abstract

    def extend(self, items):
    for item in items: self.append(item)
    , Aug 4, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthias Kaeppler
    Replies:
    1
    Views:
    436
    R.F. Pels
    May 22, 2005
  2. Sameer
    Replies:
    4
    Views:
    600
    Roedy Green
    Aug 31, 2005
  3. Aguilar, James
    Replies:
    6
    Views:
    416
    Aguilar, James
    Aug 11, 2004
  4. Replies:
    0
    Views:
    280
  5. Replies:
    4
    Views:
    811
    Rolf Magnus
    May 17, 2006
Loading...

Share This Page