PHP OOP tavsiyeye ihtiyaç

0 Cevap php

i web sitesi üyesi bazı vesileyle dayalı 10 kez ücretsiz sms göndermek olacak bu sms bildirim sisteminin, inşa ediyorum ve belli bir üye 10 kez ulaştıktan sonra, sistem bu son ücretsiz sms "diyerek son bir uyarı sistemi göndermek istiyorsunuz bildirim "i şu anda PHP OOP öğrenme ve bu bir OOP yaklasimimizi kullanmaya çalışıyorum

olmadan da benim kod yapın:

<?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 
    }
}

}
?>

olacaktır bu hatları:

$found = $this->find_member($id);
$status_check = $this->status_check($id);

(i anda yerel bu inşa ediyorum çünkü ben bu bir test edemem) beklendiği gibi çalışmıyor? ve bu OOP yaklasimimizi ilgili en iyi uygulamadır? ya da ben yanlış yapıyorum?

i, tavsiyeye ihtiyacınız çok teşekkür ederim.

EDIT:

Tabii ben sınıf bildirmek benim orijinal kod, ben burada yazılı değil herkesi şaşırtmaktadır üzgünüm: D, ben aslında ben en iyi yaklaşım (en iyi uygulama uygulamak gerektiğini yol işaret cevap bir tür (danışma) arıyorum ) Fotoğraf kodları (bu durumda yöntemlerinde), i endişelenecek şey ben böyle KISS veya DRY gibi gereksinimlerini karşılamak kalmamasıdır

UPDATE i manage to do some modifications based on your suggestions, how is this looks like ?

<?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();
?>

0 Cevap