Re: oo problem



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
.



Relevant Pages

  • Re: Design question - Abstract, base, interfaces, ack!
    ... Here is a chapter on dynamic type based class factories ... Shape class, the compiler will complain that the Draw method doesn't ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Classwide Parameter?
    ... > rewritten the code to be in one single package now): ... > package Graphics is ... what I want is to have different implementations of the Draw method ... > The Shape's Draw method is always called here but it shouldn't. ...
    (comp.lang.ada)
  • Re: Capture IWebBrowser image (call IViewObject::Draw from a different thread)
    ... Are you saying it's not possible to use the Draw method in a separate ... get 100ms delay in my render loop, so the fps are limited to 10fps. ... Why not do it the other way round: host each browser in its own worker ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Re: Dependency Inversion Principle Dilemma
    ... > external environment in order to draw their shape. ... The solution is that the draw method should draw to an ... abstract device context. ... EventStudio 2.0 - Generate Sequence Diagrams and Use Case Diagrams in ...
    (comp.lang.cpp)
  • Re: Questions about drawing on Canvas
    ... I am attempting for the first time to do some drawing on a canvas. ... Why do you subclass from JPanel to draw rectangles, ... // TODO Find out what effect removing these LOC will have. ...
    (comp.lang.java.programmer)