[Tutor] class design

Kent Johnson kent37 at tds.net
Sat Jun 6 13:02:05 CEST 2009


On Sat, Jun 6, 2009 at 5:04 AM, Norman Khine<norman at khine.net> wrote:
> Hello,
> I would like help to design the following:
> http://paste.lisp.org/display/81448

Product.get_days() may have a bug, it only returns the first container it finds.

You probably don't want the view code in the same class with the data.
It's generally a good idea to separate the model - the representation
of data - from the view - the display of the data.

The get_images() methods are all very similar. If each class had a
get_children() method then you could combine the get_images(). For
example

class Product(Folder):
  ...
  def get_children(self):
    children = [ self ]
    children.extend(self.get_itinerary())
    children.extend(self.get_days())

class Folder(object):
  def get_images(self):
    images = []
    for child in self.get_children():
      images.extend(child.search_handlers(handler_class=File))
    return images

You might be able to do something similar with get_days().

I wonder why you are not using a database to store all this? I can't
help wondering what the code would look like in Django.

Kent


More information about the Tutor mailing list