> For the complete documentation index, see [llms.txt](https://redberry.gitbook.io/resources/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://redberry.gitbook.io/resources/other/oop-obiektze-orientirebuli-daprogramireba/memkvidreobitoba/magaliti.md).

# მაგალითი

განვიხილოთ ასეთი მაგალითი. პროგრამაში გარკვეული მიზეზებიდან გამომდინარე დაგვჭირდა სამი კლასის შექნა, ესენია <mark style="color:yellow;">პროგრამისტი, დიზაინერი</mark> და <mark style="color:yellow;">ტესტერი</mark>.&#x20;

* სამივეს გააჩნიათ <mark style="color:yellow;">საერთო თვისებები - სახელი, გვარი, ხელფასი</mark>
* <mark style="color:yellow;">საერთო მეთოდი დაწინაურება</mark> ( ხელფასი იზრდება 500 ლარით).&#x20;

მაგრამ თითოეულ მათგანს ასევე გააჩნია <mark style="color:yellow;">უნიკალური თვისებები</mark> მაგალითად&#x20;

* <mark style="color:yellow;">პროგრამისტს</mark> - <mark style="color:yellow;">ფრეიმვორკი</mark>
* <mark style="color:yellow;">დიზაინერს</mark> - <mark style="color:yellow;">საყვარელი ფერი</mark>
* <mark style="color:yellow;">ტესტერს</mark> კი <mark style="color:yellow;">აპლიკაციის სახელი</mark> რომელზეც ახლა მუშაობს.

\
ამ მაგალითში ადვილად დავინახავთ მემკვიდრეობითობის მთელ რიგ უპირატესობებს. ქვემოთ იმპლემენტირებულია ამ მაგალითის კოდი მემკვიდრეობითობის გამოყენებით და მის გარეშე.

{% tabs %}
{% tab title="მემკვიდრეობითობით" %}

```php
<?php

// მშობელი კლასი
class Human {
    public string $name;
    public string $lastName;
    public int $salary;

    public function __construct(string $name,string $lastName, int $salary)
    {
        $this->name = $name;
        $this->lastName = $lastName;
        $this->salary = $salary;
    }
    
    public function promote()
    {
        $this->salary = $this->salary + 500;
    }
}

// შვილი კლასი
class Programmer extends Human{
    public string $framework;

    public function __contruct(string $name,string $lastName, int $salary, string $framework)
    {
        // საჭიროა მშობელი კონსტრუქტორის გამოძახება
        parent::__construct($name,$lastName,$salary);
        $this->framework = $framework;
    }
}

// შვილი კლასი
class Designer extends Human{
    public string $favoriteColor;

    public function __contruct(string $name,string $lastName, int $salary, string $favoriteColor)
    {
        parent::__construct($name,$lastName,$salary);
        $this->favoriteColor = $favoriteColor;
    }
}

// შვილი კლასი
class Tester extends Human{
    public string $currentApp;

    public function __contruct(string $name,string $lastName, int $salary, string $currentApp)
    {
        parent::__construct($name,$lastName,$salary);
        $this->currentApp = $currentApp;
    }
}

// მემკვიდრე/შვილი კლასის ინსტანსები ჩვეულებრივ იქმნება
$dev = new Programmer('Uncle','Bob',1000,'Laravel');
$des = new Designer('Christopher','Nolan',1000,'Dark');
$tst = new Tester('Robert','De. Niro',1000,'YouTube');

// და ჩვეულებრივ ვმუშაობთ მათთან
$dev->promote();
echo "$dev->name $dev->lastName salary - $dev->salary \n";

```

{% endtab %}

{% tab title="მემკვიდრეობითობის გარეშე" %}

```php
<?php

class Programmer {
    public string $name;
    public string $lastName;
    public int $salary;
    public string $framework;

    public function __construct(string $name,string $lastName, int $salary, string $framework)
    {
        $this->name = $name;
        $this->lastName = $lastName;
        $this->salary = $salary;
        $this->framework = $framework;
    }
    
    public function promote()
    {
        $this->salary = $this->salary + 500;
    }
}

class Designer {
    public string $name;
    public string $lastName;
    public int $salary;
    public string $favoriteColor;

    public function __construct(string $name,string $lastName, int $salary, string $favoriteColor)
    {
        $this->name = $name;
        $this->lastName = $lastName;
        $this->salary = $salary;
        $this->favoriteColor = $favoriteColor;
    }
    
    public function promote()
    {
        $this->salary = $this->salary + 500;
    }
}

class Tester {
    public string $name;
    public string $lastName;
    public int $salary;
    public string $currentApp;

    public function __construct(string $name,string $lastName, int $salary, string $currentApp)
    {
        $this->name = $name;
        $this->lastName = $lastName;
        $this->salary = $salary;
        $this->currentApp = $currentApp;
    }
    
    public function promote()
    {
        $this->salary = $this->salary + 500;
    }
}


// უბრალოდ შევქმნათ ინსტანსები და რომელიმეს რამე დავაბეჭდინოთ
$dev = new Programmer('Uncle','Bob',1000,'Laravel');
$des = new Designer('Christopher','Nolan',1000,'Dark');
$tst = new Tester('Robert','De. Niro',1000,'YouTube');

$dev->promote();
echo "$dev->name $dev->lastName salary - $dev->salary \n";

```

{% endtab %}
{% endtabs %}

ასევე უნდა აღვნიშნო ისიც, ლარაველში უკვე არაერთხელ გქონიათ მემკვიდრეობითობასთან შეხება. მაგალითად როდესაც ქმნით კონტროლერს, ის აცუილებლად აექსთენდებს შემდეგ კლასს App\Http\Controllers\Controller

![](/files/VLJNNit1Mwxr01pXXMhx)

როდესაც ქმნით ელოქვენთის მოდელს ის აექსთენდებს ელოქვენთის Model კლასს და ა.შ.

![](/files/DLEEbnmMHwT2Ln3AMP5p)
