From Wikipedia, the free encyclopedia
Bu̍t-kiāⁿ tō-hiòng têng-sek sè-kè iah-sī bīn-hiòng tùi-siōng pian-têng (Eng-gí: Object-oriented programming, OOP), tiō sī kheng-hiòng iōng bu̍t-kiāⁿ (mi̍h-kiaⁿ, tùi-siōng)--ê khài-liām lâi siá--ê têng-sek sè-kè-hoat (programming paradigm). Iōng che, lán-lâng thang kā ta̍k khoán tāi-chì iah-sī bu̍t-phín iōng "bu̍t-kiāⁿ"--ê kài-liām lâi bô͘-gí (thiu-siōng-hòa, abstraction). Bu̍t-kiāⁿ ū i kā-ki--ê sio̍k-sèng (attribution) piàn-sò͘, mā thang iōng i ka-kī--ê hong-hoat (method, chi̍t-chióng têng-sū), chiap-siu kî-tha--ê bu̍t-kiāⁿ, kap hőng thoân kap kî-tha--ê hâm-sò͘ iah-sī hong-hoat.
Bu̍t-kiaⁿ thang hun-chò kui--ê lūi-pia̍t (class), chi̍t-ê lūi-pia̍t ū i--ê sio̍k-sèng kap hong-hoat. Lē (iōng Python 3):
# tēng-gī lūi-pia̍t "Káu" class Káu: def __init__(self, name, length): '''Kiàn-li̍p "Káu" lūi-hêng lāi-té--ê bu̍t-kiāⁿ--ê sî pháng--ê hong-hoat''' '''Ē-kha sī sio̍k-sèng''' self.name = name #miâ self.length = length def pùi(self, string): '''"pùi" sī chi̍t-khoán hong-hoat''' print("%s, áu!" % string) lâi_hù = Káu("Lâi-hù", 80) # tēng-gī lâi_hù sī káu # ìn lâi_hù--ê sio̍k-sèng (miâ, ta̍t sī "Lâi-hù") print(lâi_hù.name) # sú-iōng hong-hoat "pùi", ìn-chhut "Góa sī chi̍t chiah káu, áu!" lâi_hù.pùi("Góa sī chi̍t chiah káu")
Chi̍t-ê lūi thang sī pa̍t--ê lūi--ê "kiáⁿ-lūi", kè-sêng goân-iú--ê (pō͘-hūn) sio̍k-sèng kap hong-hoat, ē-tàng hō͘ kiáⁿ-lūi lâi sú-iōng.
Bô-kâng--ê lūi-pia̍t thang ū kâng-khoán--ê hong-hoat, tio̍h sī khoán to-thàì (多態)--ê lē.
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.