Pho: Am I overdoing it with this design?
No, i dont think so. I think the Image class must be unaware of the algorithm used to serialize and this is one way of decoupling the data and behaviors.
Pho: Is there a more correct way to implementing this ?
I think you have not implemented the Strategy pattern correctly.
The problem is that you have made the Image aware of different Serializers. Since you have a Serializer interface, you can make the Image class aware only of the interface and not the implementations like JSON and XML.
In the serializeTO() method you must not pass the Format as you would have already decided upon the serializer based on the format.
You must directly call the serializers serialize method.
The code will look like this:
(Ideally, a strategy should always be of the above form.)
Now, the above will work if an image object while creation knows what it can be serialized into(otherwise you have to either pass it into the serializeTo method or keep on flipping the serializers!)
The other way can be to do an Inversion of control on this design and let the Serializer take the Image as the method argument.
(This way you can follow the
Visitor pattern in a way. This will be like a JSON/XML serializer for all the artifacts.)