Ich baue dieses SMS-Benachrichtigungssystem, das 10 Mal kostenlose SMS zu bestimmten Zeiten an das Web-Mitglied senden wird, und nachdem ein bestimmtes Mitglied 10 Mal erreicht hat, würde das System ein letztes Benachrichtigungssystem senden „dies ist der letzte freie SMS Benachrichtigung“, ich lerne derzeit PHP OOP und versuchen, eine OOP aproach auf dieserPHP OOP brauche Beratung
zu verwenden, ohne eine weitere hier nicht mein Code:
<?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
}
}
}
?>
würde diese Zeilen:
$found = $this->find_member($id);
$status_check = $this->status_check($id);
funktionieren wie erwartet (ich kann dies nicht testen, weil ich dies derzeit auf lokaler Ebene baue)? und ist dies eine Best Practice in Bezug auf OOP-Ansatz? oder mache ich das falsch?
Ich brauche Beratung, vielen Dank.
EDIT:
natürlich auf meinem ursprünglichen Code i die Klasse erklären, sie ist traurig, dass durch nicht hier schreiben verwirrt alle: D, ich bin eigentlich auf der Suche nach einer Art von Antwort (Beratung), die die spitz So sollte ich einen Best-Ansatz (Best Practice) für meine Codes (in diesem Fall Methoden) implementieren, Dinge, um die ich mir Sorgen mache ist, dass ich die Anforderungen wie KISS oder DRY nicht erfülle
AKTUALISIEREN ich schaffe es, einige Änderungen basierend auf Ihren Vorschlägen zu tun, wie sieht das aus?
<?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();
?>
ich habe meine Frage aktualisiert, wie geht's Das ? Vielen Dank – littlechad