Reputation: 88207
For a Data Access Object, what methods and arguments are there? Will a typical DAO look like
DAO<T>
+ select(): List<T>
+ selectOne(id: int): T
+ insert(obj: T): boolean
+ update(obj: T): boolean
+ delete(obj: T): boolean
If so then why not just have my Entities/Domain Objects inherit from this class? Then I wont have to pass in objects into this class. Also currently, this class seems like it will contain alot of similar code? I suppose my understanding of DAO are abit wrong? I am more familiar with ORMs
Upvotes: 2
Views: 217
Reputation: 7344
Indeed, typical DAOs are a lot like what you describe and there are libraries that help you avoid to create similar methods that differ only in type (if you implement the DAO's with an ORM, look for generic DAOs).
Frameworks like Spring-Data-JPA, for instance, let you focus on the uncommon methods of querying objects by other criteria.
findByName(String: name): List
findByDay(Date: d1, Date d1): List
Moving those methods to the entity objects is a pattern that some people prefer but precisely the point of being able to define a generic DAO and inherit from it it would be a reason to leave this methods in different classes.
So, I don't you are wrong in your understanding of DAOs.
Upvotes: 1