OOP design question

Anthony Veale' veale at fafnir.dyndns.org
Tue Jun 19 20:35:23 EDT 2001


Hello,

I'm a newbie to OOP and Python at the same time and I'm having a bit
of a design problem.  I can see at least one way out of my problem
that isn't really OO, but since I'm writing this program to learn
some OO programming, that's a bit of a cheat.  However, it might
turn out to be the most appropriate solution.  I just don't know.

Let me be concrete here.  I'm writing a program to edit the Opera 5
for Linux bookmarks file.  I designed some classes for Urls and
Folders and one for the bookmark file as a whole.  The BookmarkFile
class contains instances of Folders and Urls.

Then when I started to design the editing program, I found that
there are some features that I wanted to add to Folders, that are
really only applicable to Folders when editing the bookmark file.

So I'd like to subclass Folders and make sure that the BookmarkFile
class creates Folders using the new subclass.

The questions:
     Should I try to redesign the BookmarkFile class to use a
     parameter to control the actual class of Folder instance?  (Can
     you actually pass a class as a parameter?)

Or:
     Should I try to redesign the BookmarkFile class to be easier
     to subclass and use subclassing to control the class of Folder
     instances?

Or:
     Should I try to isolate these "editing" functions into something
     that gets mixed with the Folder class?

Or:
     Is there some other approach that I simply haven't thought of?

The cheat would be to just add the features to the Folder class
itself without subclassing.  It would work, but doesn't really seem to
be the appropriate OO action to take.  If I were writing this program
in order to get something functional, I'd probably just do it.  But
I'm trying to learn the "right way" here.

-- 
Anthony Veale'		veale at fafnir.dyndns.org
Home Alone 4-- Hardly Working



More information about the Python-list mailing list