> For the complete documentation index, see [llms.txt](https://madeindonesia.gitbook.io/mi-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://madeindonesia.gitbook.io/mi-guide/backend-things/oop.md).

# OOP

## What is OOP

Object Oriented Programming atau lebih dikenal dengan OOP adalah suatu metode atau cara penulisan Code Program yang berfokus pada orientasi object. Tujuan utama dari OOP adalah memecah Code Program kedalam bagian bagian kecil atau disebut dengan object sehingga mudah untuk di lakukan perbaikan dimasa yang akan datang.

## Prinsip Dasar OOP

Berikut prinsip - prinsip dasar dari OOP

### 1. Encapsulation

Encapsulation pada OOP merupakan suatu konsep atau cara untuk melakukan hidding dan juga protect informasi atau function dari proses interupsi sumber code yang lain.

{% code title="Encapsulation " %}

```php
class Student {
    private $firstname;
    private $gender;
   
    public function getFirstName() {
        return $this->firstname;
    }
   
    public function setFirstName($firstname) {
        $this->firstname = $firstname;
        echo("First name is set to ".$firstname);
        echo("<br>");
    }
   
    public function getGender() {
        return $this->gender;
    }
   
    public function setGender($gender) {
        if ('Male' !== $gender and 'Female' !== $gender) {
            echo('Set gender as Male or Female for gender');
        }
   
        $this->gender = $gender;
        echo("Gender is set to ".$gender);
        echo("<br>");
    }
}
   
$student = new Student();
$student->setFirstName('Meena');
$student->setGender('Female');
```

{% endcode %}

### 2. **Inheritance**

Inheritance adalah konsep untuk mewarisi suatu class kepada class lain sehingga dapat beberapa class yang berbeda dapat digunakan didalam suatu class yang sama.

{% code title="Inheritance" %}

```php
class A {
   public function insideA() {
    echo "I am in class A";
     }
}
  
interface B {
   public function insideB();
}
  
class Multiple extends A implements B {
  
    function insideB() {
        echo "\nI am in interface";
    }
  
    public function insidemultiple() {
        echo "\nI am in inherited class";
    }
}
  
$geeks = new multiple();
$geeks->insideA();
$geeks->insideB();
$geeks->insidemultiple();
```

{% endcode %}

### 3. **Abstract Class**

Abstract Class merupakan class yang tidak bisa di-instansiasi ataupun dirubah menjadi object sehingga Abstract Class Dapat perperan sebagai Kerangka Dasar bagi class turunannya. abstrack class umum nya memiliki abstract method.

{% code title="Abstract Class" %}

```php
// Abstract class
abstract class Base {
    function __construct() {
        echo "this is abstract class constructor ";
    }
  
    // This is abstract function
    abstract function printdata();
}
class Derived extends base {
    function __construct() {
        echo "\n Derived class constructor";
    }
    function printdata() {
        echo "\n Derived class printdata function";
    }
}
$b1 = new Derived;
$b1->printdata();
?>
```

{% endcode %}

## SOURCE

Kamu dapat melihat banyak contoh penggunaan yang lebih lengkap [di sini ](https://www.w3schools.com/php/php_oop_what_is.asp)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://madeindonesia.gitbook.io/mi-guide/backend-things/oop.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
