Я создаю эту систему уведомлений смс, которая будет раз в 10 раз бесплатно посылать смс на основании определенного случая члену сети, и после того, как определенный член достигнет 10 раз, система отправит последнюю систему уведомлений, сообщающую, что «этопоследнее бесплатное смс-уведомление ", в настоящее время я изучаю PHP ООП и пытаюсь использовать подход ООП для этого
без дальнейших действий, вот мой код:
<?php
class SmsBonus {
//bonus_sms fields = id, member_id, counter, end_status
public static function find_member($id=0){
//query to find a certain member
}
public function add_counter($id=0){
//query to increment the value of counter field
}
public function status_check($id=0){
//query to check whether the given member's counter has reach the number 10
}
public static function send_sms($id, $message){
$found = $this->find_member($id);
$status_check = $this->status_check($id);
if(!empty($found) && !empty($status_check) && $found->counter == 10){
//send the sms notification saying that this member has reach the end of the bonus period
//update this member's end_status table to 1
}else{
//send the regular notification
}
}
}
?>
будет это строки:
$found = $this->find_member($id);
$status_check = $this->status_check($id);
работает как ожидалось (я не могу проверить это, потому что в настоящее время я строю это на локальном)?и является ли это наилучшей практикой в отношении подхода ООП?или я делаю это неправильно?
мне нужен совет, большое спасибо.
РЕДАКТИРОВАТЬ:
конечно, в моем исходном коде я объявляю класс, извинитето, что это не написано здесь, смущает всех: D, я на самом деле ищу какой-то ответ (совет), который указал, каким образом я должен реализовать наилучший подход (лучшую практику) в моих кодах (в данном случае методы), вещи, которые ябеспокоюсь о том, что я не отвечаю таким требованиям, как KISS или DRY
ОБНОВЛЕНИЕ Мне удается внести некоторые изменения на основе ваших предложений, как это выглядит?
<?php
class SmsBonus{
//bonus_sms fields = id, member_id, counter, end_status
protected $max_sms = 10;
public $id;
public $member_id;
public $counter;
public $end_status;
public function find_member($id=0){
//query to find a certain member
}
public function add_counter($id=0){
//query to increment the value of counter field
}
public function status_check($id=0){
//query to check whether the given member's counter has reach the number 10
}
public function update_status($id=0){
//query to update when a certain member reach its sms bonus limit
}
protected function can_still_send_sms($member_id){
$found = $this->find_member($member_id);
$status_check = $this->status_check($id);
return !empty($found) && $found->counter < $this->max_sms && !empty($status_check);
}
public function send_sms($id, $message){
$phone = Phone::find_member($id); //
if ($this->can_still_send_sms($id)) {
//send the sms notification saying that this member has reach the end of the bonus period
$this->update_status($id);
}else{
//send the regular notification
$this->add_counter($id);
}
}
}
$sms_bonus = new SmsBonus();
?>