PHP OOP တွင် Interface Constants များ

Interfaces များသည် class properties များကို မပါဝင်နိုင်သော်လည်း constants များကိုတော့ ပါဝင်နိုင်ပါသည်။ Interface constants များသည် class constants များကဲ့သို့ အတိအကျ အလုပ်လုပ်ပါသည်။ သို့သော် ၎င်းတို့ကို အမွေဆက်ခံသော class သို့မဟုတ် interface များမှ ပြန်လည်သတ်မှတ်၍မရပါ။

ဥပမာအနေဖြင့် iSphere interface တစ်ခုပြုလုပ်ကြည့်ပါမည်။ ၎င်းသည် sphere (အလုံး) တစ်ခုနှင့် အလုပ်လုပ်ရန် class ကို ဖော်ပြပါမည်။ ထို sphere အတွက် ထုထည်နှင့် မျက်နှာပြင်ဧရိယာကို ရှာဖွေရန် လိုအပ်ပါမည်။ ထို့အတွက် Pi ကိန်းသေ လိုအပ်ပါမည်။ ၎င်းကို ကျွန်ုပ်တို့၏ interface ၏ constant အဖြစ် သတ်မှတ်ပါမည်။

iSphere.php<?php
  interface iSphere
  {
    const PI = 3.14; // Pi ကိန်းသေအဖြစ်
    
    // Sphere ၏ constructor:
    public function __construct($radius);
    
    // Sphere ၏ ထုထည်ကို ရှာဖွေရန် method:
    public function getVolume();
    
    // Sphere ၏ မျက်နှာပြင်ဧရိယာကို ရှာဖွေရန် method:
    public function getSquare();
  }
?>
Задание 1

iSphere interface ကို implement လုပ်မည့် Sphere class တစ်ခုကို ပြုလုပ်ပါ။