Say I've got domain objects "Order" and "FinanceRecord" which I'll use Hibernate to map to the database.
Could my code look like this? Is there anything wrong with this design?
Code:
public class Order{
//getters and setters
public void createFinanceRecord(){
FinanceRecord fr = new FinanceRecord();
fr.setOrder(this);
...
DAO.getInstance().saveOrUpdate(fr);
...
}
}
I use a DAO "DAO.getInstance()" so I'm not tied to Hibernate.
So now if I want to go without DTOs, I'd have these classes on the client side.
Therefore, I had to use a DAO so I don't need Hibernate on the client side?
So I've got this method "createFinanceRecord()" on the client side, which I can't call that contains business logic that the client shouldn't need to know about.
This is not a problem except that it's not too elegant.
If I did call createFinanceRecord() on the client side DAO.getInstance() would return null and I'd get a null pointer, which is fine.
Does this all look OK in theory?
Does anything I said not make sense?