[Tutor] Re: How do you share a method (function) among several objects?

Jeff Shannon jeffshannon at gmail.com
Sun Feb 27 23:12:06 CET 2005


On Sun, 27 Feb 2005 20:20:19 +0200, Xif <xifxif at gmail.com> wrote:
> There are two major classes:
> 
> 1) an Excel class, that represents of the whole Excel program
> 2) a Cells class, that abstracts retrieval  and editing of cells.
> 
> [...]
> 
> The difference between the 2 classes is that a Cells instance just
> converts the generator into a list and returns it:
> 
> #<code>
> return list(getCells(self.sheet, cells))
> #</code>
> 
> while an Excel instance returns the values of the cells:
> 
> #<code>
> return [cell.Value for cell in getCells(self.sheet, cells)]
> #</code>

Why not have the Excel class make use of the Cells class?  That is,
you construct a Cells object with the appropriate parameters, use it
to get the list of cells, and then iterate over that list getting
values?  You could probably find many other places in the Excel class
where it could be simplified by delegating to a Cells instance, too...

Jeff Shannon


More information about the Tutor mailing list