Oop php 5
Upcoming SlideShare
Loading in...5
×
 

Oop php 5

on

  • 1,398 views

oop

oop

Statistics

Views

Total Views
1,398
Views on SlideShare
1,398
Embed Views
0

Actions

Likes
0
Downloads
48
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Oop php 5 Oop php 5 Presentation Transcript

  • OOP PHP 5.3 Faruoqi
  • Basic
    • • Classes and objects
    • • Constructor methods
    • • Inheritance
    • • Visibility
  • 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
  • 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}"; } }
  • 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
  • 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 );
  • 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; } }
  • 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
  • Contoh static class StaticClass{ static public $nama =“oqi”; public $say = “hallo”; static public function sayHello() { return self::$nama; } } Echo StaticClass::sayHello(); Echo StaticClass::$nama;
  • 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
  • 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; } }
  • 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 ); } // ... }
  • Design pattern
    • Aggregation
    • Composition
  • Design Pattern
    • Decouple
    • Singleton
  • 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'; } }
  • Cara make class singleton echo Single::getInstance()->coba();
  • 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
  • Bersambung ke next slide faruoqi