Page 1 of 1

OOP , new objects and existing objects

Posted: Fri Feb 27, 2009 9:56 am
by Gurzi
Hello folks,

I'm learning how to use OOP , and i already know a little bit of how to use them.
But a question remains in my head, It's supposed to retrieve data from the database and put within the object ?

For example, i have a object User that can make some methods like


makeRequest() to request some file and some other methods.


But my user has attributes like name, age etc.

If it's an existing user, you can download the data from the database and put within the attributes of the object.
But the problem arises when we talk of new users. Shall i create only a constructor to receive da data of the new user as arguments and insert in the database ? Because, for me there isn't any sense to create a object user just to add the user to the database.

Thanks

Re: OOP , new objects and existing objects

Posted: Sat Feb 28, 2009 10:13 pm
by josh
That is one way. You could put an SQL query in the constructor that populates the object properties with database fields, after a while if you want to work smarter you will create abstract classes that can generate a range of queries for you. There's lots of ORM frameworks that will save you months of research & development