Re: inheriting file object

Discussion in 'Python' started by Jeremy, Jul 6, 2005.

  1. Jeremy

    Jeremy Guest

    harold fellermann wrote:
    >>I don't know if I should be inheriting file or just using a file
    >>object.
    >> How would I determine which one would be more appropriate?

    >
    >
    > Inheritance is often refered to as an IS relation, whereas using an
    > attribute
    > is a HAS relation.
    >
    > If you inherit from file, all operations for files should be valif for
    > your
    > class also. Usually the file-operations would be directly inherited and
    > not
    > overwritten.
    >
    > However, if you don't want to expose all file functionalities, a HAS
    > relation
    > is more appropriate. if you plan to use your class as a file handle,
    > e.g. for
    > formatting output in a special way, I woould prefer to make the file an
    > attribute:


    > If you would tell as your use case, it would be easier to give you an
    > advice.


    That is an excellent explanation and the example is similar to what I
    want to do. I have a file I want to look through and change if needed.
    I think I will follow you suggestion and not inherit from the file object.
    Thanks,
    Jeremy
    Jeremy, Jul 6, 2005
    #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. Fuzzyman

    Inheriting from object

    Fuzzyman, Jun 29, 2005, in forum: Python
    Replies:
    16
    Views:
    584
    Bengt Richter
    Jul 3, 2005
  2. Jeremy

    inheriting file object

    Jeremy, Jul 6, 2005, in forum: Python
    Replies:
    0
    Views:
    257
    Jeremy
    Jul 6, 2005
  3. Fabiano Sidler

    inheriting type or object?

    Fabiano Sidler, Apr 27, 2006, in forum: Python
    Replies:
    1
    Views:
    244
    James Stroud
    Apr 27, 2006
  4. Inheriting str object

    , Feb 5, 2007, in forum: Python
    Replies:
    5
    Views:
    331
    Alejandro Barroso
    Feb 6, 2007
  5. Mangabasi
    Replies:
    3
    Views:
    345
Loading...

Share This Page