Pages

Monday, February 22, 2016

oop ერთად

 კლასის გამოცხადება

<?php
class SimpleClass
{
    // property declaration  თვისებები
    public $var = 'a default value';
    // method declaration
    public function displayVar() {
        echo $this->var;
    }
}

?>




ოოპ ბაზისური კონცეფცია გულისხმობს :
აბსტრაქციას
ენკაფსულაციას
მემკვიდრეობას

პოლიმორფიზმს

Abstraction is simplifying complex reality by modeling classes appropriate to the problem.



კლასის მეთოდები და ფუნქციები შესაძლებელია იყოს:
Public (ნაგულისხმევი) საჯარო, როცა მისაწვდომია ყველგან
Protectedდაცული, როცა method / function / property მისაწვდომია მშობელ და მემკვიდრე კლასში, ან როცა მისი გამოძახება შესაძლებელია შვილობილ ან ქვეკლასში
is available to the parent class and all inheriting classes or we call them subclasses or child classes.

Private დამალული, როცა მეთოდი ჩანს მხოლოდ მშობელ კლასში  
the method is private and only available to the parent class / base class.



class Encap
{
  public $name;
   private $id;
   protected $tax;

  public function userId()
  {
  return $this->id = 786;
  }
}
$obj = new Encap();

echo $obj->userId();



მემკვიდრეობა  extends


class ParentClass {
  // properties and methods here
}

class ChildClass
extends ParentClass {
  // additional properties and methods here
}





1 comment: