OOP : เจาะแบบลึก(ง่าย ๆ) แบบคิดเองเออเอง #2

เอาล่ะมีเขียนโปรแกรมแบบ OOP กันดีกว่าพี่น้องแมว  

ก่อนอื่นประกาศ Class ก่อนน่ะ ถ้ายังไม่เข้าใจว่า Class คืออะไรก็ .. Class มันคือ กระติบข้าว ซึ้งนั้นในมีข้าวอยู่และมีข้าวหลายเมล็ดด้วย แต่ละเม็ดก็ไม่เหมือนกัน ประมาณนี้ ไม่เข้าใจก็โทรไปถามเอาแล้วกัน 

class maxcomputer{
public function __construct(){
$this->var ='';
$this->var2 = array();
$this->var3 = $this->var2;
$this->load->...
$this->??? 
}
public function set_value($param=array()){
$this->var2 = $param['param1'];
$this->var3 = $param['param2'];
$this->get_value($param);
}
public function get_value($param=array()){
$return = array(
'var1' => $this->var1,
'var2' => $this->var2,
'msg' => 'result'
);
return $return;
}// call function 


}
//อันนี้เป็นขั้นตอนของการเรียกใช้ class นี้น่ะครับ ง่าย ๆ โดยใช้คำสั่ง new มันขึ้นมา
$call_class = new maxcomputer();
// set param คำว่า พารามิเตอร์บางคือค่าที่ส่งไปบางคนก็เรียกว่าอาร์กิวเมนต์แล้วแต่จะเรียกกัน
$set_var = array(
'param1' => 'value1',
'param2' => 'value2',
);
//อันนี้เป็นการรับค่าจากสิ่งที่ได้กลับคืนมาจากที่ส่งไป
$assign_var = $call_class->set_value($set_var);
printf($assign_var['msg']);


เอาแค่นี้ก่อนแล้วกัน .. 
Share on Google Plus

About maxcom

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 ความคิดเห็น:

แสดงความคิดเห็น