Your SlideShare is downloading. ×
Oop php 5
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Oop php 5

1,223
views

Published on

oop

oop


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

  • Be the first to like this

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. OOP PHP 5.3 Faruoqi
  • 2. Basic
    • • Classes and objects
    • • Constructor methods
    • • Inheritance
    • • Visibility
  • 3. Class Content
    • Variables di deklarasikan dengan “visibility operator” dengan standart naming convention variable
    • Constants di deklarasikan dengan “const” keyword
    • Methods di deklarasikan dengan “function” keyword
    • Class hanya mempunyai satu tujuan penggunaan
  • 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 "{$this->producerFirstName}". " {$this->producerMainName}"; } }
  • 5. Object Type Hinting
    • Berguna untuk mengecek argument yang dimasukkan ke suatu fungsi adalah instance dari class tertentu .
    • Jadi hanya argument bertipe objek yang boleh masuk
  • 6. Buat ShopProductWriter class ShopProductWriter { public function write(ShopProduct $shopProduct ) { $str = "{$shopProduct->title}: " . $shopProduct->getProducer() . " ({$shopProduct->price})n"; print $str; } } $product= new ShopProduct( "My Antonia", "Willa", "Cather", 5.99 ); $writer = new ShopProductWriter(); $writer->write( $product1 );
  • 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 = "{$this->title} ( {$this->producerMainName}, "; $base .= "{$this->producerFirstName} )"; $base .= ": playing time - {$this->playLength}"; return $base; } }
  • 8. Static Method & Property
    • Fungsi atau properti yang bisa diakses tanpa harus me referensi ke objek instance dari class tersebut.
    • Jadi langsung mereferensi ke class nya
  • 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. Abstract Class
    • Class yang tidak bisa di instance langsung,jadi hanya sebagai API atau template dari class turunannya
    • Semua fungsi di abstract class yang mempunyai keyword abstract,harus dipunyai oleh class turunannya
  • 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 = "PRODUCTS:n"; foreach ( $this->products as $shopProduct ) { $str .= $shopProduct->getSummaryLine()."n"; } print $str; } }
  • 12. Interface
    • Adalah kumpulan dai fungsi yang harus dipakai jka di implementasikan oleh suatu class
    interface Chargeable { public function getPrice(); } class ShopProduct implements Chargeable { // ... public function getPrice() { return ( $this->price - $this->discount ); } // ... }
  • 13. Design pattern
    • Aggregation
    • Composition
  • 14. Design Pattern
    • Decouple
    • Singleton
  • 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. Cara make class singleton echo Single::getInstance()->coba();
  • 17. Status
    • 20% ready to learn Zend Framework.
    • Tapi kalau bisa diterusin lagi belajar Oop nya di rumah
    • PR nya:
    • lazy loading
    • late static binding
    • factory pattern
  • 18. Bersambung ke next slide faruoqi