Hello everyone,

I want to be able to use objects to create my future pages. My goal is to
use methods of classes to make the original front-line script easier to
read, while all the processing is done with a simple call to the different
classes from a single class. Please read futher, as I'll get to a point and
to my question...

I have many classes that do different tasks, like formValidator.class,
stringManipulator.class, db.class, fileManipulation.class, template.class,
etc (these are self-explanitory as their names suggest). Then, I might have
a class called category.class that adds, deletes, edits, moves, and renames
categories within the filesystem and database. But I would have a front-line
script called category.php that would call the necessary methods of
category.class at certain points, depending on the task being done on a
specific step.

In other words I want category.class to call the other classes and do
something with them, then in turn I want category.php to call objects in
category.class for a specific task, such as:

<?php

// category.php

include ("category.class");
$cat = new category ();
$cat->addCategory($new_cat_name);
// or
$cat->editCategory($cat_name);
// or
$cat->deleteCategory($cat_name);
// or
$cat->moveCategory($cat_name);
// or
$cat->renameCategory($cat_name);

?>


My question is:

How can I call a class within another class and do something with it? Right
now I'm doing it the most convenient way I know, which is including other
classes using the include() function within the methods of the
category.class. There is no multiple-inheritance allowed in PHP, so I can
only use inheritance on one class.

I am also extremely skeptical about creating too many classes at a time in
one script. Do the above examples degrade performance speed of the script
when I call too many classes? Also, isn't there a way to use sessions to
save created classes and then use them again for other scripts without the
need to make a new instance of the same class again and again?

I am really looking for a better way to organize my code while still being
able to use these classes whenever I need them and at the same time keeping
the category.php file clean and easy to read. Is there a tutorial on how to
organize code? I'm not looking for html template tutorials. Just how to get
around inheritance limits while still keeping performance and clean-code in
mind.

Here's an example of what category.class might look like:

<?php

// category.class
include ("base_db.class");
class category extends base_db {

   function addCategory {
        include ("fileManipulation.class");
        include ("formValidator.class");
        include ("stringManipulator.class");

        // Manipulate Inputted Category String
        $strMan = new stringManipulator();
        $strMan->formatCat($new_cat_name);

        // Validate Form Values
        $formVal = new formValidator();
        $formVal->addCatVal($new_cat_name);

        // Add A Folder To Hold Category Files
        $file = new fileManipulator();
        $file->createFolder($cat_path.$cat_dir);

        // And so on...
   }
}





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to