OOP PHP 5.3 Faruoqi
Basic <ul><li>•  Classes and objects </li></ul><ul><li>•  Constructor methods </li></ul><ul><li>•  Inheritance </li></ul><...
Class Content <ul><li>Variables di deklarasikan dengan “visibility operator” dengan standart naming convention variable </...
Contoh class ShopProduct {  public $title ; private $producerMainName  ;  private $producerFirstName  ;  public $price ;  ...
Object Type Hinting <ul><li>Berguna untuk mengecek argument yang dimasukkan ke suatu fungsi adalah instance dari class ter...
Buat ShopProductWriter class ShopProductWriter {  public function write(ShopProduct $shopProduct ) {  $str  = &quot;{$shop...
Inheritance class CdProduct extends ShopProduct {  public $playLength;  public function __construct(  $title, $firstName, ...
Static Method & Property <ul><li>Fungsi atau properti yang bisa diakses tanpa harus me referensi ke objek instance dari cl...
Contoh static  class StaticClass{  static public $nama =“oqi”;  public $say = “hallo”; static public function sayHello() {...
Abstract Class <ul><li>Class yang tidak bisa di instance langsung,jadi hanya sebagai API atau template dari class turunann...
Contoh abstract class abstract class ShopProductWriter {  protected $products = array();  public function addProduct( Shop...
Interface <ul><li>Adalah kumpulan dai fungsi yang harus dipakai jka di implementasikan oleh suatu class </li></ul>interfac...
Design pattern <ul><li>Aggregation </li></ul><ul><li>Composition </li></ul>
Design Pattern <ul><li>Decouple </li></ul><ul><li>Singleton </li></ul>
Contoh Singleton Sederhana class Single { private static $_ins = null; const CONFIG = 'ok juga'; protected function __cons...
Cara make class singleton echo Single::getInstance()->coba();
Status <ul><li>20% ready to learn Zend Framework. </li></ul><ul><li>Tapi kalau bisa diterusin lagi belajar Oop nya di ruma...
Bersambung ke next slide faruoqi
Upcoming SlideShare
Loading in...5
×

Oop php 5

1,289

Published on

oop

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,289
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
63
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Oop php 5

  1. 1. OOP PHP 5.3 Faruoqi
  2. 2. Basic <ul><li>• Classes and objects </li></ul><ul><li>• Constructor methods </li></ul><ul><li>• Inheritance </li></ul><ul><li>• Visibility </li></ul>
  3. 3. Class Content <ul><li>Variables di deklarasikan dengan “visibility operator” dengan standart naming convention variable </li></ul><ul><li>Constants di deklarasikan dengan “const” keyword </li></ul><ul><li>Methods di deklarasikan dengan “function” keyword </li></ul><ul><li>Class hanya mempunyai satu tujuan penggunaan </li></ul>
  4. 4. Contoh class ShopProduct { public $title ; private $producerMainName ; private $producerFirstName ; public $price ; public function __construct( $title, $firstName, $mainName, $price ) { $this->title = $title; $this->producerFirstName = $firstName; $this->producerMainName = $mainName; $this->price = $price; } public function getProducer() { return &quot;{$this->producerFirstName}&quot;. &quot; {$this->producerMainName}&quot;; } }
  5. 5. Object Type Hinting <ul><li>Berguna untuk mengecek argument yang dimasukkan ke suatu fungsi adalah instance dari class tertentu . </li></ul><ul><li>Jadi hanya argument bertipe objek yang boleh masuk </li></ul>
  6. 6. Buat ShopProductWriter class ShopProductWriter { public function write(ShopProduct $shopProduct ) { $str = &quot;{$shopProduct->title}: &quot; . $shopProduct->getProducer() . &quot; ({$shopProduct->price})n&quot;; print $str; } } $product= new ShopProduct( &quot;My Antonia&quot;, &quot;Willa&quot;, &quot;Cather&quot;, 5.99 ); $writer = new ShopProductWriter(); $writer->write( $product1 );
  7. 7. Inheritance class CdProduct extends ShopProduct { public $playLength; public function __construct( $title, $firstName, $mainName, $price, $playLength ) { parent::__construct( $title, $firstName, $mainName, $price ); $this->playLength = $playLength; } public function getPlayLength() { return $this->playLength; } public function getSummaryLine() { $base = &quot;{$this->title} ( {$this->producerMainName}, &quot;; $base .= &quot;{$this->producerFirstName} )&quot;; $base .= &quot;: playing time - {$this->playLength}&quot;; return $base; } }
  8. 8. Static Method & Property <ul><li>Fungsi atau properti yang bisa diakses tanpa harus me referensi ke objek instance dari class tersebut. </li></ul><ul><li>Jadi langsung mereferensi ke class nya </li></ul>
  9. 9. Contoh static class StaticClass{ static public $nama =“oqi”; public $say = “hallo”; static public function sayHello() { return self::$nama; } } Echo StaticClass::sayHello(); Echo StaticClass::$nama;
  10. 10. Abstract Class <ul><li>Class yang tidak bisa di instance langsung,jadi hanya sebagai API atau template dari class turunannya </li></ul><ul><li>Semua fungsi di abstract class yang mempunyai keyword abstract,harus dipunyai oleh class turunannya </li></ul>
  11. 11. Contoh abstract class abstract class ShopProductWriter { protected $products = array(); public function addProduct( ShopProduct $shopProduct ) { $this->products[]=$shopProduct; } abstract public function write(); } class TextProductWriter extends ShopProductWriter{ public function write() { $str = &quot;PRODUCTS:n&quot;; foreach ( $this->products as $shopProduct ) { $str .= $shopProduct->getSummaryLine().&quot;n&quot;; } print $str; } }
  12. 12. Interface <ul><li>Adalah kumpulan dai fungsi yang harus dipakai jka di implementasikan oleh suatu class </li></ul>interface Chargeable { public function getPrice(); } class ShopProduct implements Chargeable { // ... public function getPrice() { return ( $this->price - $this->discount ); } // ... }
  13. 13. Design pattern <ul><li>Aggregation </li></ul><ul><li>Composition </li></ul>
  14. 14. Design Pattern <ul><li>Decouple </li></ul><ul><li>Singleton </li></ul>
  15. 15. Contoh Singleton Sederhana class Single { private static $_ins = null; const CONFIG = 'ok juga'; protected function __construct() { } public static function getInstance(){ if(!isset(self::$_ins)){ self::$_ins = new self(); } return self::$_ins; } public function coba(){ return 'ok'; } }
  16. 16. Cara make class singleton echo Single::getInstance()->coba();
  17. 17. Status <ul><li>20% ready to learn Zend Framework. </li></ul><ul><li>Tapi kalau bisa diterusin lagi belajar Oop nya di rumah </li></ul><ul><li>PR nya: </li></ul><ul><li>lazy loading </li></ul><ul><li>late static binding </li></ul><ul><li>factory pattern </li></ul>
  18. 18. Bersambung ke next slide faruoqi
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×