Good Morning (Afternoon, evening, i dunno what time it is when ur reading this .. lol but its 8:30 AM here :) )
I was yesterday in a Meetup about android programming and The presenter had a sample code about how to create an app with database access in android..
We talked about various classes, methods and so on.
Lets assume we have a table in the database called MyItem .. We create a class called MyItem.java that has the same fields (similar to object relational mapping concept).
Now the presenter created a class called MyItemList.java that goes like this
package androidenthusiasts.androiddbproject;
import java.util.ArrayList;
// The MyList class is used to store MyItem objects in an ArrayList
public class MyList {
public ArrayList<MyItem> mylist;
// NonParameterized Constructor - Called when class is created
public MyList()
{
mylist = new ArrayList<MyItem>();
}
// AddItem method
public boolean AddItem(MyItem item)
{
mylist.add(item);
return true;
}
// GetCount method
public int GetCount()
{
return mylist.size();
}
// getItem method
public MyItem getItem(int index)
{
MyItem item = null;
if (index < GetCount())
{
item = mylist.get(index);
}
return item;
}
}
This is an object that only has a list.. and all the methods implemented are in the ArrayList .. Is it a good practice to create a new object for this list? Is it better to define the ArrayList wherever you want to use it as an ArrayList? Or even more, should we create a class for MyItem that extends the ArrayList?
What do the masses of StackOVerFlow Think?
Thanks