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. Advertisements

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:
    670
    R.F. Pels
    May 22, 2005
  2. Sameer
    Replies:
    4
    Views:
    844
    Roedy Green
    Aug 31, 2005
  3. Aguilar, James
    Replies:
    6
    Views:
    530
    Aguilar, James
    Aug 11, 2004
  4. Uzytkownik
    Replies:
    3
    Views:
    742
    Uzytkownik
    Apr 3, 2005
  5. Replies:
    0
    Views:
    339
  6. Replies:
    4
    Views:
    1,065
    Rolf Magnus
    May 17, 2006
  7. scg_
    Replies:
    6
    Views:
    483
    Noah Roberts
    Feb 3, 2009
  8. Marcel Müller
    Replies:
    2
    Views:
    275
    Marcel Müller
    Mar 15, 2014
Loading...