Let's say I have a list of Person with some attributes. For each object in this list I want to create a new Person object but only based on some of its attributes.
The Person object has the following attributes : age, name, disease. I want to create a new Person only on its age and name. The disease attribute must be confidential.
How could I do that ?
Thanks in advance !
You very easily could do this by creating a new object entirely which does not hold that information. For example, you could make a class such as this
public class PersonNoDisease {
private int age;
private String name;
...
}
If you want to make sure that PersonNoDisease still has many of the same methods that the original person class did, you should create an interface that they both implement to ensure that they both have the methods which you think they should both have. If you don't have getters in the Person class, you should make those so that it will be easier to initialize this new class.