I want to provide general functionality between various types of operations, such as opening and closing a database connection. Consider the following class:
public class DataActivity extends Activity {
private DbAdapter mDbAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDbAdapter = new DbAdapter(this);
mDbAdapter.open();
}
@Override
protected void onDestroy() {
super.onDestroy();
mDbAdapter.close();
}
public DbAdapter getDbAdapter() {
return mDbAdapter;
}
}
Then I could just expand DataActivityand access my data throughout the class. However, what if I wanted to do this for ListActivityor ExpandableListActivity? I need to make a copy DataActivityand expand it.
This seems really messy if you have several classes with duplicate implementation code for each type of activity to which I would like to add this.
Edit
, , , , - , Java ( ). , .