aspose file tools*
The moose likes Java in General and the fly likes How to implement this structure? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to implement this structure?" Watch "How to implement this structure?" New topic
Author

How to implement this structure?

Michael Lars
Greenhorn

Joined: May 12, 2012
Posts: 20

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
Michael Lars
Greenhorn

Joined: May 12, 2012
Posts: 20

? anyone ?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8427
    
  23

Michael Lars wrote:? anyone ?

<comment removed>

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?
Articles by Winston can be found here
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8427
    
  23

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.

Winston
Michael Lars
Greenhorn

Joined: May 12, 2012
Posts: 20

Ok, sorry for the caps lock.

All I want is to connect this two diagrams.

Thanks!


[Thumbnail for img.png]

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8427
    
  23

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.

Winston
Michael Lars
Greenhorn

Joined: May 12, 2012
Posts: 20

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!
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8427
    
  23

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.

Winston
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to implement this structure?