We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
PGraphics interface? (Read 2205 times)
PGraphics interface?
Oct 5th, 2005, 1:48am
 
Hi,

This is a suggestion/question about the guts of Processing.
I'm right now coding a library and I'm running into a little problem.
I have in my library some classes which I would like to contain a function draw(PGraphics g) in order to allow them to draw "themselves" in any given PGraphics, PGraphics2, PGraphics3, PGraphicsGL object we pass to them.  So I have must I implement three different draw() methods with three different signatures each time?

I think it would be better having a PGraphicsInterface and all the PGraphics* implement from.  That would allow people to implement their own PGraphics renderers and other people access those objects transparently without knowing the renderer, like my case.

I just saw, that PGraphics* extend from PGraphics, so it should work with one only signature for draw().

But I still don't understand why not having an interface and implementing it for each different renderer. It seems like the academic example for making use of interface Wink.  But then, I'm quite a beginner and maybe I'm missing something.

Thanks for the aclarations.
Re: PGraphics interface?
Reply #1 - Oct 5th, 2005, 2:45am
 
right, they all subclass PGraphics, so there's no need for an interface.

the fact that it's an "academic" example of why to use an interface is part of why we're not. it adds abstraction with no benefit. an additional class file that doesn't actually solve any practical issue. it seems cleaner but just makes more overhead.

the various implementations also share variables, which can't be done with an interface.
Re: PGraphics interface?
Reply #2 - Oct 5th, 2005, 3:54pm
 
You're right about the interface creating unbeneficious overhead.
And this cleared out a lot about the "spirit" of processing.  So it made me change a few things in my library, in order to make it simpler, but keeping the functionality we want to keep.

In a week or two I'll publish an Alpha (changes in the API might happen) version of the library.

thanks
Page Index Toggle Pages: 1