Search code examples
javasubclassradix

Create subclass just to convert between different subclasses


I found something which I had never think about before when going through the code base of the new company I just joined. Basically this what happens: we have a base class which represents say an Image with several abstract methods to convert between different image types. The different image types are subclasses of the base Image class. Subclasses are responsible for converting between different images which are all derived classes.

My question is is this supposed to be a good design? if not what alternatives can we have?

Thanks a lot.


Solution

  • If I designed the scenario then I would do the following.. ( N.B i am not a very good designer, just sharing my concepts)

    1. a base class image with abstract methods which wil only represent the behavior not any actions to convert
    2. subclasses implementing those abstract classes which define the behaviors
    3. other utility class which have methods which convert between different images.