Interface in PHP | OOP public methods implementation | structure & contract in programming #kody_az

PHP

Dərs haqqında

PHP-də interfeys (interface) — siniflər üçün bir qaydalar toplusudur. Yəni interfeys bir müqavilə (kontrakt) kimi işləyir və bildirir ki, bu interfeysi qəbul edən hər bir sinif müəyyən metodları mütləq şəkildə yazmalıdır. Amma interfeysin özündə heç bir kod yazılmır, yalnız metod adları və parametrləri göstərilir.

Interfeysin məqsədi ondan ibarətdir ki, fərqli siniflər eyni strukturu izləsin və eyni cür davransın. Beləliklə, sistemin müxtəlif hissələri bir-birindən asılı olmadan eyni interfeys üzərindən işləyə bilər.

• Interfeyslər yalnız metodların adını və parametrlərini təyin edir, içində heç bir məntiq (kod) yoxdur.
• Bütün interfeys metodları default olaraq public-dir.
• Interfeysi qəbul edən sinif bu metodların hamısını özündə yazmalıdır.
• Bir sinif bir neçə interfeysi qəbul edə bilər.
• Interfeyslər bir-birini genişləndirə (extend edə) bilər.

Təsəvvür et ki, interfeys bir televizorun pultudur. Hər bir pultda düymələr var: açıb-söndürmək, səsi artırmaq, kanalı dəyişmək və s. Müxtəlif televizorlar və ya proyektorlar eyni düymələrə fərqli reaksiya verə bilər, amma hamısı eyni interfeysi dəstəkləyir. Beləliklə, fərqli cihazları eyni pultla idarə etmək olur.

======

An interface in PHP is a blueprint for classes. It defines a set of method names and signatures that any class implementing the interface must define, but it does not contain any logic or code itself.

The purpose of an interface is to ensure that different classes follow the same structure or “contract”, which is especially useful when different classes need to behave in a similar way.

• An interface defines only method names (no actual code).
• All methods in an interface are public by default.
• A class that implements an interface is required to define all the methods in the interface.
• One class can implement multiple interfaces, allowing flexible code organization.
• Interfaces can extend other interfaces to build more complex contracts.

Think of an interface as a remote control. It defines the buttons: power, volume, channel, etc. Different devices like TVs or projectors may implement that interface differently, but they still respond to the same set of buttons. This way, you can use any remote with a device as long as both follow the same interface.

#kody_az #kodyaz #php #phpcode #laravel #phpprogramming #viral #viralcode #viralvideo #random #code #coder #azerbaycan #azerbaijan #baku #baki #programming #programmer #codes #hazırlıq #hazirliq #kurs #kurslar #course #courses #online #onlinecourses #test #quiz

YouTube-da bax · KODY.AZ