interface Button is
method render()
method onClick(f)
class WindowsButton implements Button is
method render(a, b) is
// Windows uslubidagi tugmachani ko'rsatish.
method onClick(f) is
// Windows voqea ishlovchilarini tugmachaga ulash.
class HTMLButton implements Button is
method render(a, b) is
// Tugmaning HTML kodini qaytaring.
method onClick(f) is
// Brauzer voqealari ishlovchilarini tugmachaga ulash.
// Zavodning asosiy klassi. E'tibor bering, "zavod" bu sinf uchun qo'shimcha rol. // Ehtimol, u allaqachon turli xil mahsulotlarni yaratishni talab qiladigan biznes // mantig'iga ega.
class Dialog is
method render() is
//Factory method usulidan foydalanish uchun ushbu biznes mantig'ining ma'lum //mahsulot sinflaridan mustaqil bo'lishiga ishonch hosil qilishingiz kerak. //Tugma - tugmachalarning umumiy interfeysi, shuning uchun hammasi yaxshi.
Button okButton = createButton()
okButton.onClick(closeDialog)
okButton.render()
// Biz mahsulotlarni yaratish uchun barcha kodlarni "zavod" deb nomlangan //maxsus usulga o'tkazamiz.
abstract method createButton():Button
// Factory method qayta aniqlanadi va o’z elementlarini qaytaradi
class WindowsDialog extends Dialog is
method createButton():Button is
return new WindowsButton()
class WebDialog extends Dialog is
method createButton():Button is
return new HTMLButton()
class Application is
field dialog: Dialog
// Ilova konfiguratsiyaga yoki xatti-xarakatga qarab ma'lum bir Factory methodni //yaratadi.
method initialize() is
config = readApplicationConfigFile()
Dostları ilə paylaş: |