I'm doing a project that should be stored in two differents text files. Let say I have 2 classes Person and Activity, each with only these attributes in common: id and isActive. But there are also many that are not common.
Also I have 2 classes ArrayList type:
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;
}
//more methods
}
.
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;
}
//more methods
}
Both classes have the same methods
As you see both classes type ArrayList RegitryPerson and RegistryActivigy have same methods, but some used different kind of object.
I just don't wanna have almost same code in differents classes. Can I use an interface or abstract class? and most important, How can implement that?. Or I am complicating everything?
Thanks.