I have concluded using the DAO design is best for what I am trying to achieve, but I have never tried it befor so I am having a bit of trouble. I've read documentation and examples so I know what the goal is but I am having a hard time figuring out what I need to include in my DAO interfaces.
For example I have a Model object that has:
public String name;
public double baseline;
public List<Group> groups;
public List<Indicator> indicators;
I don't know exactly how I'd create the DAO interface for this though? Do I just put every method I'd think I'd need in there because I know the DAOImpl class is going to have the actual queries to the NoSQL database.
This is where it stands right now:
public interface ModelDAO {
List<Model> getAllModels();
List<Model> getModelByName(String Name);
void updateModel(Model model);
void deleteModel(Model model);
}
But for example what if I want to update the name of the model, or add/remove a group from the list of groups? Are those things that I would take care of inside this DAO class? Or would I address those inside of their respective DAO classes.
Sorry if my understanding isn't fully there yet, I am still trying to learn this stuff.
You could implement that either way you wanted. The important thing is to make sure that objects are responsible for what you want them to be. The interface acts as a connector between the DAO and other objects, so you need to make sure that anything that another object needs to do can be done using methods in the interface. However, if you put every accessor and mutator in the interface, then there is no point using it, and you could just make the functions all public (in other words, if you do that, you are not using a true DAO at all.) Generally speaking, a DAO should not be used if you have other objects that would be highly coupled with through the interface. If you decide tht you want to stick with the DAO structure, you should have a small number of method swhich perform any changes you need. for example, if you need to change a field called 'name' you wouldnt call 'setName()' you would instead modify the name field in the other object, then call 'updateFields()' through the interface (or something like that.) Hope that helps, sorry for the wall of text, its a complex question to answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With