mercredi 14 décembre 2016

Implementing new feature using SOLID principles in old code

I just try to get more into SOLID principles but get stuck by implementing new structures in my old (not SOLID) code.

I have this Room.Class

public class Room {
   private String roomCode;
   private String roomDescription;
   // getter/setter
}

Now I need to have a translation for the roomDescription. I started to create an interface

public interface ITranslation {    
    String findTranslation();    
}

and an implementation

public class RoomDescriptionTranslation implements ITranslation {

@Override
public String findTranslation() {
    return "translated Room";
}

In the already existing code there is a service class which creates some Rooms with codes and descriptions. These Rooms are also used in the view (as jsp bean).

The new requirement is to have the translated description on the view.

So for me the question is where I should implement the logic of translation of the existing Rooms.

  • Should I implement it in the existing serivce class where the Rooms are created?
  • Or should RoomDescriptionTranslation be a field inside Room?
  • Or should I created a new service class where just the description gets translated?

Just need a pointer to go to the right direction.

Aucun commentaire:

Enregistrer un commentaire