I have to attend a "software engineering" exam this Friday, but there's a little thing I can't understand, and my teacher is unavailable for explaining.
I must make a project based on the Boundary-Controller-Entity (BCE) pattern, with persistence (database or sequential file, but I'm going to use SQLite). I should implement entity classes with save/load methods, which put/retrieve data in/from the persistence layer. They use DAO.
For example:
public class someEntity
{
private int someData;
public void set_someData (int _someData) {this.someData = _someData;}
public int get_someData () {return this.someData;}
public void save ()
{
DAO dao = new DAO ();
dao.openConnection ();
dao.insert (this.someData);
dao.closeConnection ();
}
Thus far, it's all clear.
When I implement the "load" method, I want to "fill" my entity instance with data from the database, using search parameters (primary key in DB). But, if, for example, I want to get all people born before 1980, what can I do?
The only solution in my mind is to implement the following, into controller class
ArrayList <people> pList= new ArrayList ();
people p;
for (int i = 1900 ; i < 1980 ; i++)
{
p = new people ();
if (p.load (i) == true); //returns true if has found corresponding entry in db
{
pList.add(i);
}
}
This is totally insane, is it not?
So, I need a "loader" method that returns a collection, so I can implement in the DAO a method that returns all people born before 1980, with a simple SQL query. Can this be done only if the control class talks directly with the DAO, ignoring BCE pattern rules.
How can I resolve the problem, if it is a real problem?