lundi 2 novembre 2015

Design pattern for display DTO objects

I am new to design patterns and I have the following need: I have a set of events represented by DTO objects like: LateEventDTO, RescheduleEventDTO,etc. Each of these DTO objects have their own set of properties. Right now, I have an abstract class called EventDTO and all different types of DTO objects like LateEventDTO,RescheduleEventDTO,etc extend the EventDTO.

I will be passing one of these DTO objects to my ui layer (jsp page) which checks what type of DTO object it is. Like this:

if(event instance of Late){
  //handle late event and display it's content
}

else if(event instance of Reschedule){
   //handle reschedule event and display it's content
}

And so on and so forth.

What i want is to make the presentation layer oblivious to the different type of eventDTO objects. All it needs to do is get a generic object and display it's contents. It shouldn't check for it's type explicitly like i showed above.

What would be the best design pattern for this scenario?

Aucun commentaire:

Enregistrer un commentaire