1-amali mashg’ulot: Pattern loyihalashda “Factory Method”


Download 349.83 Kb.
bet2/3
Sana30.04.2023
Hajmi349.83 Kb.
#1415820
1   2   3
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()



Download 349.83 Kb.

Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling