samedi 7 septembre 2019

Correct choice of design pattern for indifferent request types

Having a very interesting problem here on design. Building an API which does scanning on the request that is being passed to scan API. Currently there are 2 types of request and they are totally different from one another. API has to support both of these requests. Also the design should work well if any new request is introduced in future.

Request 1:

class EmployeeReq {
      String name;
      String id;
      //getter,setter for the parameters.
      getName(); setName(name);
      getId(); setId(id);
}

Request 2:

class StudentReq {
      String studentName;
      String grade;
      //getter,setter for the parameters.
      getStudentName(); setStudentName(studentName);
      getGrade(); setGrade(grade);
}

API: MyRequest: is either EmployeeReq or StudentReq, based on what client will send.

public MyResponse scan(MyRequest req) {
     //scan the request based on what parameters being passed as request.
     /**
     The scan engine should scan the req fields coming in.
     Which can be getName(); getId(); getStudentName(); getGrade();
     How can I achieve to access the different scan fields from different Request types at once place? 
     **/

}

Aucun commentaire:

Enregistrer un commentaire