Hello!
I'm trying to implement a simply java image editor, but i can't find a good solution!
So, i have an interface PICTURE with some methods. PNG, GIF etc implements Picture interface.
Now i want a PNGEDITOR that can work on PNG type. And the same for other formats.
I have tryed different patterns but is not working.
Any idea how can i arrange this?
Thank you
If it was me, I'd probably look to have PngEditor (and classes should be named that way, not in all-caps) implement a generalized Editor or ImageEditor interface. Then your Picture deals with an Editor, which you can specify at implementation time.
That said, we'll need a lot more information if we're to help you much further.
Winston
Isn't it funny how there's always time and money enough to do it WRONG?
Winston Gutkowski wrote:Michael, you should EaseUp (←click)...
Michael,
My apologies. It was pointed out by a colleague that there was two weeks between your posts (I didn't look properly, and assumed they were from the same day), and that does seem fair to query.
I've removed the offending comment but left it here for posterity.
Michael Lars wrote:All I want is to connect this two diagrams.
What? Figuratively or literally?
If you actually want to join two images together than I suspect that your editor has to have a 'join' or 'paste' function. If, given an image of a particular type, you simply want to launch the correct Editor class, then you need something to "know" which one to choose. If you can't edit the image class itself, then you'll need to either:
(a) Wrap it, or
(b) Write a 3rd-party class (or perhaps an enum) that can do the translation.
actually I want that the PngEditor can "use/work" only the concrete Png Class, and the same for the other. This have to be extensible because i have a lot types of "Images".
Does the abstract pattern work in this case?!
Thanks!
Michael Lars wrote:actually I want that the PngEditor can "use/work" only the concrete Png Class, and the same for the other. This have to be extensible because i have a lot types of "Images".
Does the abstract pattern work in this case?!
I think you mean the abstract factory pattern; and yes, it could work providing all your Editors implement the same interface (ImageEditor?).
As to extensible: is an enum 'extensible' enough? If I couldn't actually put that knowledge in the image class itself, it's probably the way I'd do it - ie, have an enum value for each image type that knows what its Editor is - at least on my first cut.