-
When programming in Java is it always necessary to code according to the DAO architecture? If so what are advantages of using it?
-
I’m doing a project which has a class diagram like below. what are the disadvantages of this?

Entity Class:
private void fillSONumber() {
try {
ZnAlSalesOrder o = new ZnAlSalesOrder();
ArrayList a = o.getPendingSalesOrderIDs();
for (int i = 0; i < a.size(); i++) {
cmbSoNo.addItem(a.get(i));
}
o.close();
} catch (Terminated ex) {
}
}
EntityTable Class Example:
public ResultSet select(String fields, String selection) {
db = new Database();
db.select("SELECT " + fields + " FROM " + name + " WHERE " + selection);
return rs = db.rs;
}
and the database class do the connection establishment and destroying.
The purpose of a DAO pattern is to separate what data you are trying to access from how it is stored.
For example, you could create a DAO that specifies a number of methods that you then implement against MySQL. If you ever decide you need to move to MSSQL or Oracle, you only need to change the implementation, not the interface that could be used in a number of different places in your code.
It is not necessary to do this, but it can be a good idea to make future changes easier and keep your code decoupled.
As for your design, the basic layout is fine, but I would recommend against a generic select method like you have. You are basically just creating another layer of abstraction where something could go wrong without any extra benefit.
It will work well for simple queries, but if you need to do any joins, you will quickly end up with a large mess of methods for different join types.
It is better to just write your SQL for each type of data you need to access and create a method that returns the type of data you want. This reduces your coupling and allows you to change your implementation if needed.