Which is considered a generally accepted practice?
class Image {
public void decode();
};
//main
Image image;
image.decode();
vs
class ImageDecoder {
public Image run(Image image);
};
//main
Image image;
ImageDecoder decoder;
Image decoded = decoder.run(image);
In other words, are these "worker classes" that accept objects as parameters a good practice, or should methods be called directly on objects whenever possible? Is this just a matter of opinion, or is there any general agreement which design pattern is better? How are these patterns called and where can I read more?
If I wanted to manipulate some essential property of the Image such as its size (width, height), Image::resize() would definitely be the way because implementing an ImageResizer class would not make sense. In the example above I am not so sure. After all, decoding an image for further use (converting it to another type, for example) is nowhere near the inherent functionality of an Image.
Please note the code above is just an example. My question is about a good OOP design.