. , . name age.
interface PersonInput {
public String getName();
public int getAge();
}
Person
class Person {
public Person(PersonInput input) {
name = input.getName();
age = input.getAge();
}
}
PersonInput, (CSV, XML ..).
JSON:
class JsonPersonInput implements PersonInput {
private String name;
private int age;
public JsonPersonInput(String json) throws JSONException {
JSONObject data = new JSONObject(json);
name = data.getString("name");
age = data.getInt("age");
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
}
new Person(new JsonPersonInput(jsonString))