oo problem

tool69 kib2 at free.fr
Wed Dec 13 07:15:25 EST 2006


Hi,
First, let me thanks you for all your clear comments.


> 
>         This is, in my mind, both a usage and a design flaw. 
> 
>         You are creating (and throwing away) instances of drawable
> objects to the draw method of a paper instance. But what does
> paper.draw() actually do with the drawable object? Call a draw method
> within it?

No, actually the paper instance is a subclass of a canvas from an 
external module. And this one have a stroke() method.
In reading your comments, I think it's now clear that I must get back 
and let any primitive have an inner draw() method ( a subclass of 
Drawable object in our case).

> If so, that is when you should pass the paper instance (or
> just the part needed -- clipping rectangle perhaps?).

In fact, my approach was a bad one : in initialising the paper instance, 
I was already clipping it.
If I wrote : p = Paper(-5,-5,5,5), all drawings made on that paper will 
be clipped inside a rectangle with lower-left corner (-5,-5) and 
upper-right corner (5,5).
Now, I think it's better to clip after all primitives have been added to 
the paper.

> 
>         The actual implementation of draw() for each primitive will have
> to handle clipping to the boundaries of the Canvas object that is passed
> to it.
> 
>         You'll notice that the only place the primitive needs to know
> about the canvas is in its specific draw method. And only at that time
> is the canvas (paper) passed to it.
> 
>         Instead of the concept; 
> 
> Paper, draw a line from x to y 
> 
> (and having to pass the "paper" to the initializer of the line
> primitive), you have to think in terms of: 
> 
> Line, draw yourself on this paper 
> 
>         Or, if you consider the last example above… Compare that to your
> example: 
> 
> -=-=-=-=- 
> paper.draw( Line( paper, x1, y1, x2, y2)  ) 
> -=-=-=-=-=- 
> 
>         Here, you are telling the paper to do the drawing, and passing
> it a Line instance (and passing it the paper it is supposed to be drawn
> on). Why? The paper isn't drawing the line on itself… While
> 
> -=-=-=-=- 
> Line(Point(x1, y1), Point(x2, y2)).draw(paper) 
> -=-=-=-=- 
> 
> initializes a Line instance, then asks it to draw itself using paper as
> the surface to be drawn upon. 

Yes I was wrong, that's all clear now.
Thanks again, this was very helpfull.

6TooL9



More information about the Python-list mailing list