Which one to use and why in OOP ?
Posted: Sat Feb 24, 2007 7:53 am
I am wondering to know which one to use and why in OOP
scenario:
suppose i had a class named category.class.php
1st method:
2nd method
3rd Method:
and i used this class in the category.php as
1st method:
2nd method
3rd method
Above i mentioned the ways of writing classes and implementing it, whic is the best
method of applying the OOP method for sake of clarity..
Thanks in advance to all of you !!!!!!!!!!!!!!!!
scenario:
suppose i had a class named category.class.php
1st method:
Code: Select all
<?php
class category
{
// without creating properties
function insertNew($catName,$catDesc,....)
{
//insert into database goes here...
}
}
?>Code: Select all
<?php
class category
{
// with creating properties
var $catName;
var $catDesc;
var ....;
function insertNew()
{
//insert into database goes here...
}
}
?>Code: Select all
<?php
class category
{
var $catName;
var $catDesc;
var ....;
//creating constructor
function category($catName,$catDesc,..)
{
$this->catName = $catName;
$this->catDesc = $catDesc;
.......
}
function insertNew()
{
//insert into database goes here...
}
}
?>1st method:
Code: Select all
<?php
include "category.class.php";
//get the parameters from the user inputs
//creating object
$catOBJ = new category();
$catOBJ->insertNew($catName,$catDesc,....);
?>Code: Select all
<?php
include "category.class.php";
//get the parameters from the user inputs
//without creating obj
category::insertNew($catName,$catDesc,....);
?>Code: Select all
<?php
include "category.class.php";
//get the parameters from the user inputs
$catOBJ = new category($catName,$catDesc,....);
$catOBJ->insertNew();
?>method of applying the OOP method for sake of clarity..
Thanks in advance to all of you !!!!!!!!!!!!!!!!