Slide 1

Slide 1 text

Zope Component Architecture Presented by Ucok Freddy Marpaung [email protected] Python-ID Meetup Jakarta, 26-Oct-2013

Slide 2

Slide 2 text

Apa itu ZCA? ● Konsep pemograman berbasiskan komponen di python ● Dapat disejajarkan dengan: – Microsoft COM (C++) – JavaBean (Java) – Mozilla XPCOM (Generic)

Slide 3

Slide 3 text

Pendekatan OOP ● Pemograman berbasiskan object (Object Oriented Programming): – Subclassing – Delegation (Components)

Slide 4

Slide 4 text

Subclassing class Buku(object): def __init__(self, judul): self.judul = judul self.halaman = 0 def hitung_tebal(self): return self.halaman * 3 >>> buku1 = Buku('buku1') >>> buku1.halaman = 50 >>> buku2 = Buku('buku2') >>> buku2.halaman = 100 buku1 50 buku2 100 class BukuTebal(Buku): def cetak_ketebalan(self): print self.hitung_tebal() print “ketebalan buku %s milimeter >>> buku1 = BukuTebal('buku1') >>> buku2 = BukuTebal('buku2') buku1 0 buku2 0 cetak_ketebalan() cetak_ketebalan()

Slide 5

Slide 5 text

Delegation (Components) ● Component adalah object yang mendeklarasikan Interface object a component interface object an object

Slide 6

Slide 6 text

Interface ● interface adalah dokumentasi yang menjelaskan secara dekripsi kemampuan suatu object ● kemampuan suatu object identik dengan attribute dan fungsi yang dimiliki object tersebut buku1 ITebal class ITebal (Interface): halaman = Attribute('Berapa banyak halaman') def cetak_ketebalan(): “””Mencetak ketebalan suatu benda””” >>> buku1.cetak_ketebalan() 50 milimeter >>>

Slide 7

Slide 7 text

Create Interface from zope.interface import Interface, Attribute class ITebal(Interface): halaman = Attribute('Berapa banyak halaman) def hitung_tebal(): “””Hitung ketebalan suatu benda dari halaman””” >>> coba = ITebal() Traceback (most recent call last): File “”, line 1, in TypeError: Required argument 'obj' (pos 1) not found >>>

Slide 8

Slide 8 text

Create Component from zope.interface import implements from interfaces import Itebal class Buku(object): implements(ITebal) def __init__(self, judul): self.judul = judul self.halaman = 0 def hitung_tebal(self): return self.halaman * 3 >> from zope.component import implementedBy >> ITebal.implementedBy(Buku) True >> buku1 = Buku('buku1') >> buku1.halaman = 50 >> buku2 = Buku('buku2') >> buku2.halaman = 100 >> from zope.component import providedBy >> ITebal.providedBy(buku1) True buku1 ITebal buku2 ITebal

Slide 9

Slide 9 text

Extending Component buku1 50 buku2 100 cetak_ketebalan() Create another Component: Content View Component buku1 50 cetak_ketebalan() buku2 100 cetak_ketebalan() Results: Adapted Components

Slide 10

Slide 10 text

ZCA Ecosystem.