abstract class AbstractFrom {
int id ;
String name;
public abstract String getName();
public abstract int getId();
}
class ModelForm extends AbstractFrom {
int id;
String name;
public ModelForm(int id, String name) {
this.id = id;
this.name = name;
}
@Override
public String getName() {
return name;
}
@Override
public int getId() {
return id;
}
}
// ...
abstract class AbstractFrom {
int id ;
String name;
}
class ModelForm extends AbstractFrom {
int id;
String name;
public ModelForm(int id, String name) {
this.id = id;
this.name = name;
}
}
class OtherModelForm extends AbstractFrom {
int id;
String name;
public OtherModelForm(int id, String name) {
this.id = id;
this.name = name;
}
}
class MySQL {
void save(AbstractFrom form) {
System.out.println("Saved form with id = " + form.id + " and name = " + form.name);
// Saved form with id = 0 and name = null
}
}
class WebFrameWork {
void save(AbstractFrom form) {
MySQL db = new MySQL();
db.save(form);
}
}
public class DIP {
public static void main(String[] args) {
ModelForm modelForm = new ModelForm(1, "firstForm_name");
OtherModelForm otherModelForm = new OtherModelForm(5, "secondForm_name");
WebFrameWork webFrameWorkSecond = new WebFrameWork();
webFrameWorkSecond.save(modelForm);
webFrameWorkSecond.save(otherModelForm);
}
}
ExecutorService executor = Executors.newSingleThreadExecutor();
Handler handler = new Handler(Looper.getMainLooper());
executor.execute(new Runnable() {
@Override
public void run() {
//Background work here
handler.post(new Runnable() {
@Override
public void run() {
//UI Thread work here
}
});
}
});