Object Interface dalam Pemrograman Berbasis Objek PHP

Object Interface dalam Pemrograman Berbasis Objek PHP

Object Interface dalam Pemrograman Berbasis Objek PHP

Object Interface dalam Pemrograman Berbasis Objek PHP

Jika pada artikel sebelumnya kami pernah membahas mengenai pemograman berbasis objek PHP, kali ini, kami akan membahas lanjutan artikel tersebut yaitu tentang object interface. Secara sederhana, object interface adalah sebuah kontrak atau perjanjian implementasi method. Bagi class yang menggunakan object interface, class tersebut harus mengimplementasikan ulang seluruh method yang ada di dalam interface. Object interface ini sangat mirip dengan abstract class, walaupun secara konsep dan tujuan penggunaannya berbeda.

Seperti abstract class, interface berisi signature dari method, yakni hanya nama method dan parameternya saja (jika ada). Isi dari method akan dibuat ulang di dalam class yang menggunakan interface. Jika kita menganggap abstract class sebagai kerangka atau blue print dari class-class lain, maka interface adalah implementasi method yang harus tersedia dalam sebuah objek.

Membuat Object Interface dalam PHP

Untuk membuat interface di dalam PHP, kita menulisnya mirip seperti membuat class, tetapi menggunakan keyword interface, seperti contoh berikut:

1
2
3
4
5
6
<?php
interface mouse
{
   //...isi dari interface mouse
}
?>

Isi dari interface adalah signature method (nama dan parameter method):

1
2
3
4
5
6
7
8
<?php
interface mouse{
   public function klik_kanan();
   public function klik_kiri();
   public function scroll();
   public function double_klik();
}
?>

Untuk menggunakan method ke dalam class, kita menggunakan keyword implements, seperti contoh berikut:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
interface mouse{
   public function klik_kanan();
   public function klik_kiri();
}
 
class laptop implements mouse{
   //... isi dari class laptop
}
 
class pc implements mouse{
   //... isi dari class pc
}
?>

Berikut adalah beberapa hal yang harus kalian ketahui dari interface:

1. Method interface harus diset sebagai public
2. Interface bisa diturunkan (Inherit)
3. Interface bisa memiliki konstanta
4. Interface tidak bisa memiliki method normal
5. Sebuah class bisa menggunakan banyak interface

Demikianlah pembahasan mengenai object interface dalam pemograman berbasis objek. Semoga bermanfaat.

Presented By Jakartawebhosting.com

JakartaWebHosting

JakartaWebHosting

You may also like...

64 Responses

  1. December 7, 2021

    adult sex games party https://cybersexgames.net/

  2. December 10, 2021

    turning stone online casino https://casinoonlinek.com/

  3. December 12, 2021

    top online casino reviews https://casinogamesmachines.com/

  4. December 13, 2021

    raging bull casino online https://conline-casinos-hub.com/

  5. December 13, 2021

    fastest payout online casino usa https://onlinecasinos4me.com/

  6. December 13, 2021

    new online casino with free signup bonus real money usa https://online2casino.com/

  7. December 13, 2021
  8. December 13, 2021

    secure online casino https://casinosonlinex.com/

  9. December 15, 2021

    birch benders keto pancake mix https://ketogenicdietinfo.com/

  10. December 15, 2021
  11. December 16, 2021

    write a reflective essay https://topessayswriter.com/

  12. December 16, 2021

    persuasive writing essay https://yoursuperessay.com/

  13. December 17, 2021

    write persuasive essay https://howtowriteessaytips.com/

  14. December 17, 2021

    writing a literature essay https://checkyouressay.com/

  15. December 17, 2021

    dating site for gay cd https://gayprideusa.com/

  16. December 17, 2021

    gay kink dating https://gayfade.com/

  17. December 17, 2021

    best dating description for gay https://gaysugardaddydatingsites.com/

  18. December 19, 2021

    critical thinking definition easy https://criticalthinkingbasics.com/

  19. December 19, 2021

    good examples of critical thinking https://criticalthinkinginstitute.com/

  20. December 19, 2021

    explain critical thinking https://criticalthinking2020.net/

  21. December 19, 2021
  22. December 19, 2021

    college essay examples https://choosevpn.net/

  23. December 20, 2021
  24. December 20, 2021

    another word for however in an essay https://tjvpn.net/

  25. June 22, 2022

    2feasibility

  26. July 4, 2022

    2ganymede

  27. July 5, 2022
  28. July 5, 2022
  29. July 5, 2022

    18 month doctorate without dissertation https://dissertationwritingcenter.com/

  30. July 6, 2022

    creative writing course in mumbai https://accountingdissertationhelp.com/

  31. July 6, 2022

    masters dissertation help https://examplesofdissertation.com/

  32. July 6, 2022

    custom dissertation writing service 2019 https://writing-a-dissertation.net/

  33. July 6, 2022

    doctoral dissertation writing help https://bestdissertationwritingservice.net/

  34. July 6, 2022

    writing methodology for dissertation https://businessdissertationhelp.com/

  35. July 6, 2022
  36. July 6, 2022
  37. July 6, 2022
  38. July 6, 2022

    writing a dissertation methodology https://dissertationhelperhub.com/

  39. July 7, 2022
  40. July 25, 2022

    mohegan online casino https://download-casino-slots.com/

  41. July 25, 2022

    caesars online casino customer service phone number https://firstonlinecasino.org/

  42. July 25, 2022

    lucky 7 casino online https://onlinecasinofortunes.com/

  43. July 25, 2022

    online games casino https://newlasvegascasinos.com/

  44. July 26, 2022
  45. July 26, 2022

    empire city casino online https://onlinecasinosdirectory.org/

  46. July 26, 2022

    most legit online casino https://9lineslotscasino.com/

  47. July 26, 2022

    vegas 777 online casino https://free-online-casinos.net/

  48. July 26, 2022

    online casino games win real money https://internet-casinos-online.net/

  49. July 26, 2022
  50. July 26, 2022

    borgata online casino promo code https://1freeslotscasino.com/

  51. July 26, 2022

    vegas casino online $100 no deposit bonus codes 2021 https://vrgamescasino.com/

  52. July 26, 2022
  53. July 27, 2022

    the best online casino https://casino-online-jackpot.com/

  54. July 27, 2022

    borgata online casino app https://onlineplayerscasino.com/

  55. July 27, 2022

    vegas online casino https://ownonlinecasino.com/

  56. July 27, 2022

    riversweeps online casino login page https://all-online-casino-games.com/

  57. July 27, 2022

    real money casino online no deposit https://casino8online.com/

  58. August 7, 2022

    free vpn for windows 10 https://freevpnconnection.com/

  59. August 7, 2022

    zenmate vpn free https://shiva-vpn.com/

  60. August 7, 2022

    business class vpn service https://freehostingvpn.com/

  61. August 7, 2022

    what is vpn service https://ippowervpn.net/

  62. August 7, 2022

    private vpn free https://imfreevpn.net/

  63. August 8, 2022

    free vpn for roobet https://superfreevpn.net/

  64. August 8, 2022