Jump to content

can this be called as data access object class?


mweldan

Recommended Posts

That is a data access abstraction layer in interface form.

To keep it simple, a DAO separates the business logic from the persistence layer and provides the basic CRUD operations at an object level.

The most basic question when beginning to think about DAO's is what specific object are you creating a DAO pattern for?

Link to comment
Share on other sites

I want to simplify create,retrieve,update,delete process using pdo

 

the class later can be extend to provide methods for specific object

 

similar to model concept on common mvc web frameworks.

 

eg: User, Item

 

I have no idea if I get lost on understanding this pattern. Is what I am doing is on right track?

Link to comment
Share on other sites

PDO is a persistence layer itself, simplifying a persistence layer is creating an persistence abstraction layer of your own and does not require an interface. Since you are wanting to implement PDO, you could either implement the inheritance method instead of a DAO, or create a UserDao class and an ItemDao class for example versus an interface and have them implement the PDO persistence abstraction layer that you are building currently.

Link to comment
Share on other sites

So interface it not required at all?

 

Ok will remove it. Thanks

 

I actually want to know about DAO, so I try to create one.

 

It seems I have gotten far out from what I want to achieve.

 

I did some google search about it and found someone else try to achieve same thing and name it as ORM (object relational mapper) .

 

In your opinion, is it what I try to do now can be called as ORM? (or poor version of ORM?. Hehe )

 

And if can, I need examples for DAO in PHP if any.

 

Thanks for your answer.

Edited by mweldan
Link to comment
Share on other sites

Before I can adequately answer your questions and go off on a tangent about ORMs and DAOs, I first need to know what exactly it is that you are trying to achieve.

I noted that you are attempting to create a DAO, but is that the root of what you are trying to do or is there something else?

Link to comment
Share on other sites

The first is a DAO, the second is an ORM.

 

A DAO (Data Access Object) is essentially an OO interface (meaning a way to interact with and not the language construct interface) to a database. It's methods are generally your basic CRUD and anything else not app-specific.

 

An ORM (Object Relational Mapper) is a mechanism to translate objects into database data and back again. So, let's say you had a User object that had a person's name, age, gender, and a list of groups they belonged to (for site permissions or whatever). An ORM would map (the 'M') that data to actual database rows and columns.

 

An ORM is more complex than a DAO because it needs to keep track of how the data in a particular object is related. In my User example, the list of groups would come from another database table than the other User information.

 

An ORM could use/extend a DAO. The second link you gave mashes the two into one class, which is simple, but not necessarily flexable.

Link to comment
Share on other sites

So I think what I want is actually ORM.

 

This is what I want to do:

 

1. create a class to simplify usage of PDO, have some functions to make it easy to query database

2. extend that class in a class that specifically uses for objects or tables. as far i understand similar to what model in mvc structure (sorry because this is the only one i familiar with)

 

Thank you for your answer.

Link to comment
Share on other sites

Then it sounds like you want to create a persistence abstraction layer on top of the PDO layer and create DAOs that "implement" the custom persistence layer.

DAOs can be as large or as small as you want them to be, just remember that they should only handle the basic CRUD operations for a particular object.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.