我正在尝试熟悉OOP。到目前为止,我知道如何制作类方法,继承,静态等。我正在制作酒店预订系统(非常基础)。
问题是,按照我对实现OOP方法的理解,但是如果我做对与否,我仍然感到困惑。功能正常,但我对结构不满意。
我制作了一个类数据库,客户,房间这些是非常基本的类,例如数据库具有connect和断开连接方法以及静态函数run();。运行sqli查询。
在客户和房间类中,我有CRUD方法,基本上使用不同参数调用数据库static run()方法来执行我的操作。
我做对了吗?现在,我必须为我的应用程序以及房间预订模块创建用户。我应该如何使它前进..我丢失了我应该在用户课程中放置的内容以及在预订中应该保留的内容../
基本上我没有什么主意。.什么时候我们意识到必须上一堂课?
如果我创建了一个用户类并使用了方法login()logout()可以吗?
我认为我并不是在准确地描述自己,但考虑到我是初学者,我想你会让我感到困惑。
太感谢了。
示例类:
<?php
class Customers {
/*
* Declaring properties
*/
private $customer_id;
private $customer_name;
private $customer_cnic;
private $customer_address;
private $customer_email;
private $customer_phone;
/**
* View customers list
* @return array of rows
*/
public function View_Customers() {
$result = Database::Run("SELECT * FROM customer");
$rows = array();
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}
public function View_Single_Customer($Id) {
$result = Database::Run("SELECT * FROM customer WHERE id=" . $Id);
$rows = array();
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}
/**
* Add a new customer
* @param array $arg
* return last insert id on success
*/
public function Add_Customer($arg) {
$this->customer_name = $arg[0];
$this->customer_cnic = $arg[1];
$this->customer_address = $arg[2];
$this->customer_email = $arg[3];
$this->customer_phone = $arg[4];
$result = Database::Run("INSERT INTO customer (name,cnic,address,email,phone)
VALUES ('" . $this->customer_name . "','" . $this->customer_cnic . "','" . $this->customer_address . "',
'" . $this->customer_email . "','" . $this->customer_phone . "')");
return mysqli_insert_id(Database::$connection);
}
/**
* Delete a specific customer
* @param int or array of ids $id
* return affected rows on success
*/
public function Delete_Customers($id) {
$result = Database::Run("DELETE FROM customer WHERE id IN ($id)");
return $id;
}
/**
* Update existing customer based on id
* @param array $arg
* return id of updated record
*/
public function Update_Customer($arg) {
$this->customer_id = $arg[0];
$this->customer_name = $arg[1];
$this->customer_cnic = $arg[2];
$this->customer_address = $arg[3];
$this->customer_email = $arg[4];
$this->customer_phone = $arg[5];
if ($result = Database::Run("UPDATE customer SET name='" . $this->customer_name . "', cnic='" . $this->customer_cnic .
"', address='" . $this->customer_address . "', email='" . $this->customer_email . "', phone='" . $this->customer_phone . "' WHERE id=" . $this->customer_id)) {
return 'Record with id '.$this->customer_id.' has been updated ';
}
}
}
在可以为该类型的每个对象指定一组特定的属性和方法时,请创建一个类。例如,我在学校的住房和餐饮服务部门从事Web开发工作,我们正在为RSVP流程做准备,该流程即将“上线”
我们有几个阶段,在每个阶段中,允许学生根据特定条件对房间进行RSVP(优先选择)。每个阶段都具有相同的信息,例如开始日期/时间,结束日期/时间,阶段名称,数据库中该阶段的ID,以及一个数组,该数组为具有以下特征的学生保存甚至更具体的开始日期/时间与我们一起住(我们的宿舍或公寓)指定的学期数。
为此,我创建了一个包含所有这些属性的Phase类-无需修改每个Phase的属性或属性已更改的位置,它们只需要对Phase类进行更改并添加/删除/修改现有的属性和功能即可。 。这样可以节省时间编码。
要了解OOP,请阅读有关Enapsulation的信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句