Re: Missing interfaces in Python...

Discussion in 'Python' started by Jonathan Daugherty, Apr 17, 2006.

  1. # so with interfaces, missing methods will suddenly appear out of thin
    # air ?

    With interfaces, the idea is that they're enforced; so, they'll appear
    because someone implements them.

    --
    Jonathan Daugherty
    http://www.parsed.org
    Jonathan Daugherty, Apr 17, 2006
    #1
    1. Advertising

  2. Jonathan Daugherty

    Guest

    Thanks for the responses...Looks like I might have opened Pandora's box
    here. Could I accomplish the above with an abstract class?

    If the mechanic class had a "fixIt()" method defined, could I pass it
    any object I wanted, and then just call the method that I expect to
    find there, or do I need to strictly define the type, or class, of an
    object that is passed to a method.

    Scott Huey
    , Apr 17, 2006
    #2
    1. Advertising

  3. # Thanks for the responses...Looks like I might have opened Pandora's
    # box here. Could I accomplish the above with an abstract class?

    Zope 3 has an interface system which is good. I recommend you look at
    that.

    --
    Jonathan Daugherty
    http://www.parsed.org
    Jonathan Daugherty, Apr 17, 2006
    #3
  4. wrote:

    > If the mechanic class had a "fixIt()" method defined, could I pass it
    > any object I wanted


    absolutely.

    > and then just call the method that I expect to find there


    yes.

    > or do I need to strictly define the type, or class, of an object that is
    > passed to a method.


    no. this is Python. no need to negotiate with the compiler; just do what
    you want, and the interpreter will tell you when that doesn't work.

    also see:

    http://en.wikipedia.org/wiki/Duck_typing

    </F>
    Fredrik Lundh, Apr 17, 2006
    #4
  5. Jonathan Daugherty

    Benji York Guest

    Jonathan Daugherty wrote:
    > # Thanks for the responses...Looks like I might have opened Pandora's
    > # box here. Could I accomplish the above with an abstract class?
    >
    > Zope 3 has an interface system which is good. I recommend you look at
    > that.


    Zope 3's interface system is quite good, but it's also quite different
    from what he's probably expecting. On the up side, it's probably much
    better than what he's expecting too. :)
    --
    Benji York
    Benji York, Apr 17, 2006
    #5
  6. Jonathan Daugherty

    Serge Orlov Guest

    Jonathan Daugherty wrote:
    > # so with interfaces, missing methods will suddenly appear out of thin
    > # air ?
    >
    > With interfaces, the idea is that they're enforced; so, they'll appear
    > because someone implements them.


    But if you're writing tests you will check method signatures anyway, so
    why bother? Besides how java-like interfaces will help you if one of
    interface methods is supposed to accept one parameter that can be list
    or dict and not accept None?
    Serge Orlov, Apr 17, 2006
    #6
    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. Thomas Weholt

    Interfaces in python

    Thomas Weholt, May 6, 2004, in forum: Python
    Replies:
    3
    Views:
    326
    Michael Hudson
    May 7, 2004
  2. Replies:
    43
    Views:
    897
    bruno at modulix
    Apr 24, 2006
  3. Gary Herron
    Replies:
    2
    Views:
    657
    Bruno Desthuilliers
    Jul 4, 2006
  4. jmDesktop
    Replies:
    9
    Views:
    307
    jmDesktop
    May 12, 2008
  5. jmDesktop
    Replies:
    25
    Views:
    513
    Pete Forman
    May 13, 2008
Loading...

Share This Page