Hi.
I'm dealing with the following situations and I would like some opinions on both subjects. Thanks.
1 -
Is it ok to use recursive functions with OOP?
Something like
class whatever {
function whatever () {
$this->whatever_one = 1;
}
function whatever_recursive ( $a ) {
whatever;
this->whatever_recursive ( $a );
}
I'm asking because I've been told that OOP makes things slower. Does it get too slow?
2 -
Database
I have a database with two tables
articles
article_draft
Articles is where users post ARTICLES. But sometimes the user wants to start writing on "friday" and only end it some days latter, so there's the table article_draft where the user keeps saving his article draft.
The tables are very similar (main diference is that the "articles" table has the DATE and the APROVED fields.
This is how it works:
--- The user choses either to save as ARTICLE or as Draft.
--- If the user choses ARTICLE, it goes to the ARTICLE table, waiting for the admin to aprove it.
--- If the user choses DRAFT, it goes to the draft table. The user can access it latter in a special page that lists his drafts.
--- At any time the user can send his draft to be approved.
--- The system puts the draft in the ARTICLE table [inserting the date] and deletes the record on the DRAFT table.
The thing is: should I use only one table?
I think two tables is better because it prevents the article table from being filled up with "work in progress articles".
I could use one table, inserting a "is_draft" field in it.
What do you guys think? What should be the criteria to decide this kind of things (number of diferent fields, others?)?
3- Regarding the previous
There are modules with several functions that deal with those tables. If I use the TWO table approach, should I use one or two modules?
I could use ONE module with INSERT, DELETE, EDIT functions, passing an argument that identifies the table where it's suppose to go.
I could just create two modules, but that means that a considerable part of similar code is replicated.
On the other hand, if I want to use to ARTICLE module on a latter project that doesn't include the DRAFT, the code will have a bunch of conditions checking for the table. I could deal with that using something like
function insert ( $table, $data_array ) {
insert into $table
}
Instead of conditions.
Well, what do you think it's best?
Thanks.