oo problem

Tool69 kibleur.christophe at gmail.com
Tue Dec 12 10:42:53 EST 2006


Dennis Lee Bieber a écrit :

> On 10 Dec 2006 03:47:21 -0800, "Tool69" <kibleur.christophe at gmail.com>
> declaimed the following in gmane.comp.python.general:
>
> > Thanks for your answers,
> > I though about the first solution too, but I've redundant code, say ie:
> > p = Paper(100,200)
> > p.draw( Rectangle(p,10,20,50,60) ) <-- we're forced to write 'p' two
> > times.
> >
>
> 	I'd suggest not passing an instance initialization to your "Paper"
> draw() method...
>
> p = Paper(100, 200)
> p.add(Rectangle(10, 20, 50, 60))
> p.add(OtherPrimitives())
> p.draw()
>
> where p.draw() (Paper.draw(self) really) does something like:
>
> 	self.whatever_is_needed_for_Paper_itself
> 	for prm = self.primitives:	#list of stuff from p.add(...) calls
> 		prm.draw(self)			#pass current paper to the primitive
> 								#which draws itself on the paper
> 								#and can do whatever calculations
> 								#(CLIPPING perhaps) needed

Thanks for all your comments and suggestions.
Denis, I would like to know how I can made a draw method for a
primitive without a Paper instance inside ...that's always the same
problem as only my Paper instance knows the Paper sizes !




More information about the Python-list mailing list