dimanche 27 septembre 2015

Different methods needs different attributes in one object

i have the following szenario:

I have a given webservice (this is only a example, the real one is more complex but same problem.) The serivce has three methods and all three methods have a person as parameter and need other things from it. (Cant change the entity or methods.)

Entity (Person) (Have only a default construtor):

private String name;
private int age;
private Address address;
private List<String> hobbies;
private List<Person> friends;

Method1 needs name and age
Method2 needs address name and age
Method3 needs all

I need to fill the object from my own objects. I need to write a "converter" what is the best practise for it?

My solutions:

  • Builder Pattern with builds for three methods.
  • Set all attributes and send unhandled overhead (bad solution in my eyes)

Thank you for help

Aucun commentaire:

Enregistrer un commentaire