is this how you do OO programming?
Posted: Tue Jul 26, 2005 5:17 am
Hi,
if you take a look at the following code, you'd notice that i have declared a class named table.
So, when i want to instanciate an object of that class i write:
that produces the following html code:
and then what? you need to put some content in between "<table> </table>" tags right?
So I added some contents right after the object declaration code:
Okay, do you see any reason why I should do all these hard work to do OO programming?
What if i just typed </table> instead of writing a class and declaraing an object and then calling a function of that object?
Am I on the right track? Do you make all html objects each a distinct class? i.e table class, div class etc.
Is it logical? or it's better to do some part of programming using OO technique and some part of procedurally?
And any general guidelines as to how you use OO techniques to build a web site? Did i do something wrong so far in my code?
Thanks
if you take a look at the following code, you'd notice that i have declared a class named table.
Code: Select all
<?php
#
#
#
#version 1.0
#@crazytopu
#
$pageLayout = new PageLayout();
class PageLayout{
//====INTERNAL VARIABLES=========================================
private $page_title='SoftBangla Business Automation Ltd';
private $css_file_href='main.css';
private $greeting_message= 'THE FUTURE PERSPECTIVE OF IT SERVICES';
private $text_line='';
//====CONSTRUCTOR=================================================
function __construct(){
$this->buildLayOut();
}
//===PUBLIC METHODS===============================================
public function buildLayOut(){
$this->buildBeginingHtml();
//$container= new Table('10%',500,1,left,'#ff0000');
$this->buildEndingHtml();
}
//====PRIVATE METHODS=============================================
private function buildBeginingHtml(){
echo "<html>";
echo "<head>";
echo "<title>".$this->page_title."</title>";
echo "<link rel='stylesheet' type='text/css' href= '$this->css_file_href' ";
echo "</head>";
echo "<body>";
echo "<div id='topbar1'> </div> ";
echo "<div id='topbar2'> </div> ";
echo "<div id='container'> ";
echo "<div id='greetingbar'>";
echo "<span class='greetingText'>$this->greeting_message</span> </div>";
echo "<div id='image'> </div>";
echo "<div id='bottombar'> </div>";
echo "</div>";
echo "<div id='footer' > </div>";
}
private function buildcontent(){
$this->text_line.='Hello';
echo "";
}
private function buildEndingHtml(){
echo '</body></html>';
}
}
class Table{
//=====INTERNAL VARIABLES=============================================
private $border='0';
private $cellspacing='0';
private $cellpadding='0';
private $width='0';
private $height='0';
private $alignment='';
private $bgcolor='white';
//==== CONSTRUCTOR=====================================================
function __construct($w, $h, $b,$align,$bgclr){
$this->width=$w;
$this->height=$h;
$this->border=$b;
$this->alignment=$align;
$this->bgcolor=$bgclr;
echo "<TABLE BGCOLOR='$this->bgcolor' ALIGN='$this->alignment' CELLSPACING='$this->cellspacing' CELLPADDING='$this->cellpadding' BORDER='$this->border' WIDTH='$this->width' HEIGHT='$this->height'> ";
}
//=====PUBLIC METHODS==================================================
public function setBorder($n){
$this->border=$n;
}
public function setCellPadding($n){
$this->cellpadding=$n;
}
public function setCellSpacing($n){
$this->cellspacing=$n;
}
public function setWidth($n){
$this->width=$n;
}
public function setHeight($n){
$this->height=$n;
}
}
?>So, when i want to instanciate an object of that class i write:
Code: Select all
$container= new Table('100%',500,1,center,'#ff0000');that produces the following html code:
Code: Select all
<TABLE BGCOLOR='#ffOOOO' ALIGN='center' CELLSPACING='0' CELLPADDING='0' BORDER='1' WIDTH='100%' HEIGHT='500'>So I added some contents right after the object declaration code:
Code: Select all
$container= new Table('100%',500,1,center,'#ff0000');
//my html contents go here
//more content
//more content
//now i need to close the table object so the </table> tag appears.
//so what do i do? i call the function close?
$container.close(); //lets assume the close function returns "</table>"Okay, do you see any reason why I should do all these hard work to do OO programming?
What if i just typed </table> instead of writing a class and declaraing an object and then calling a function of that object?
Am I on the right track? Do you make all html objects each a distinct class? i.e table class, div class etc.
Is it logical? or it's better to do some part of programming using OO technique and some part of procedurally?
And any general guidelines as to how you use OO techniques to build a web site? Did i do something wrong so far in my code?
Thanks