I am new to java programming and am trying to understand the correct way to implement the DAO design pattern. Here’s an example, I have an itemCatalog class that includes the populateItemCatalog and searchitemCatalog methods. The item catalog was implemented using an array of type item objects.
Now I want to switch to an DAO design to access the same data from an ms-access database. My question is what becomes of these methods now as the DAO is doing the searching of the database. Do I modify them to return the DTO from the DAO. Hope my question is clear. thanks
As you say; now you want to fetch the same data from a different DB. Such cases DAO pattern suits ideally.
Now your implementing classes will have to implement above (sample) interface. Just make sure that you design the interface in such a way that it can be used by all implementing classes.
So as you asked can you return DTO. Yes, you should return DTO or list of DTO as per your requirement. It’s good practice to return an Object from your DAO. This way you abstract your implementation and it supports use of generics as well.