# მაგალითი

განვიხილოთ ასეთი მაგალითი. პროგრამაში გარკვეული მიზეზებიდან გამომდინარე დაგვჭირდა სამი კლასის შექნა, ესენია <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

![](https://392590438-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrgmjFj4NNSsoaQmAk09Z%2Fuploads%2Fa0YUbYsGRqPrz3Osb1yb%2Fimage.png?alt=media\&token=fff6f272-02d6-455c-bb9f-be5c86bf4525)

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

![](https://392590438-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrgmjFj4NNSsoaQmAk09Z%2Fuploads%2FC9J0gHmGbZ9WNRhNJk9b%2Fimage.png?alt=media\&token=55a92118-6672-4c9f-af28-344f99f996f4)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://redberry.gitbook.io/resources/other/oop-obiektze-orientirebuli-daprogramireba/memkvidreobitoba/magaliti.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
