I am making a project that should be stored in two different text files. Let's say I have 2 classes Person and Activity, each of which contains only these attributes: id and isActive. But there are many who are not common.
I also have 2 types of ArrayList:
public class RegistryPerson extends ArrayList<Person> {
public void add(Person obj){
....
}
public boolean isDuplicate(Person obj){
for(Person p: this){
if(obj.equals(p)){
return true;
}
}
return false;
}
public Person search(int id){
....
}
public void readFile(){
otherClass.readFile(String txtfilePerson);
}
public void activate(Person obj){
obj.setActivate;
}
}
.
public class RegistryActivity extends ArrayList<Activity> {
public void add(Activity obj){
....
}
public boolean isDuplicate(Activity obj){
for(Activity p: this){
if(obj.equals(p)){
return true;
}
}
return false;
}
public Activity search(int id){
....
}
public void readFile(){
otherClass.readFile(String txtfileActivity);
}
public void activate(Activity obj){
obj.setActivate;
}
}
Both classes have the same methods.
As you can see, both classes of type ArrayList RegitryPerson and RegistryActivigy have the same methods, but some use a different type of object.
I just don't want to have almost the same code in different classes. Can I use an interface or an abstract class? and most importantly, how to implement this ?. Or am I complicating things?
Thank.