Qhov Tseem Ceeb Qhov txawv - Thaum Ntxov vs Late Binding
Kev khi thaum ntxov thiab lig khi yog ob lub ntsiab lus ntsig txog Polymorphism. Lub Early Binding tshwm sim ntawm lub sijhawm sib sau thaum Lub Caij Nplooj Ntoos Hlav tshwm sim thaum lub sijhawm ua haujlwm. Qhov sib txawv tseem ceeb ntawm Early thiab Late Binding yog qhov Early Binding siv cov ntaub ntawv hauv chav kawm los daws txoj kev hu thaum Late Binding siv cov khoom los daws txoj kev hu.
Cov lus programming xws li Java txhawb Object Oriented Programming (OOP). Nws yog ib tug paradigm uas tso cai rau tsim cov kev pab cuam los yog cov software siv cov khoom. Muaj ntau yam khoom hauv software. Cov khoom no txuas nrog rau ib leeg thiab hla cov lus siv txoj hauv kev. Txhua yam khoom muaj tus yam ntxwv thiab tus cwj pwm. Cov yam ntxwv tau piav qhia los ntawm cov khoom lossis cov cwj pwm. Cov kev coj cwj pwm tau piav qhia los ntawm cov txheej txheem. Cov khoom Tub Kawm ntawv tuaj yeem muaj cov yam ntxwv xws li lub npe, hnub nyoog thiab lawv sawv cev los ntawm cov khoom. Cov khoom Tub Kawm tuaj yeem muaj tus cwj pwm xws li kev kawm thiab nyeem, thiab lawv tau sawv cev los ntawm cov txheej txheem. Ib tug ncej loj ntawm OOP yog Polymorphism. Nws tso cai rau ib qho khoom coj los ua ntau yam. Early Binding thiab Late Binding yog ob lub ntsiab lus hauv Polymorphism. Cov txheej txheem overloading yog sib koom siv thaum ntxov. Cov txheej txheem overridden yog sib cog lus siv lig khi.
Yuav Ua Li Cas Thaum Ntxov?
Nyob rau hauv Early Binding, cov ntaub ntawv hauv chav kawm yog siv los daws txoj kev hu. Early Binding tshwm sim thaum lub sij hawm sau. Nws kuj tseem hu ua static binding. Nyob rau hauv cov txheej txheem no, kev khi tau tshwm sim ua ntej qhov kev zov me nyuam ua haujlwm. Cov txheej txheem overloading yog sib koom siv thaum ntxov. Xa mus rau qhov program hauv qab no.
Daim duab 01: Chav Kawm suav
Daim duab 02: Txoj Haujlwm Tseem Ceeb rau Kev Sib Tw Thaum Ntxov
Raws li cov kev pab cuam saum toj no, chav kawm suav suav muaj ib txoj hauv kev ntxiv uas lees txais ob tus lej suav thiab lwm txoj kev ntxiv uas lees txais ob qhov txiaj ntsig. Hauv qhov kev zov me nyuam tseem ceeb, ib qho khoom ntawm hom Kev Sau Ntawv raug tsim. Thaum dhau ob tus lej rau tus lej ntxiv, nws yuav hu rau tus lej ntxiv uas lees txais ob tus lej. Thaum dhau ob qhov tseem ceeb rau txoj kev ntxiv, nws yuav hu rau txoj kev sib raug rau ob qhov tseem ceeb. Txoj kev khi no tshwm sim thaum lub sijhawm sau. Tag nrho cov ntaub ntawv xav tau yog paub ua ntej lub sijhawm ua haujlwm, yog li nws ua kom cov haujlwm ua haujlwm tau zoo thiab ua tiav nrawm.
Dab tsi yog kev khi lig?
In Late Binding, cov khoom siv los daws txoj kev hu. Late Binding tshwm sim ntawm lub sijhawm ua haujlwm. Nws tseem hu ua dynamic binding. Hauv cov txheej txheem no, kev sib khi tshwm sim ntawm qhov kev ua tiav. Cov txheej txheem overridden yog sib koom ua ke siv lig khi. Xa mus rau qhov program hauv qab no.
Daim duab 03: Cov Qauv Chav
Daim duab 04: Lub voj voog chav kawm
Daim duab 05: Daim duab peb sab
Daim duab 06: Cov kev pabcuam tseem ceeb rau Kev Sib Tw Late
Raws li cov kev pab cuam saum toj no, chav kawm Shape muaj ib txoj kev kos. Chav Kawm Vajvoog thiab chav kawm daim duab peb sab txuas ntxiv rau chav kawm Shape. Yog li ntawd, ob chav kawm no tuaj yeem tau txais cov cwj pwm thiab cov txheej txheem ntawm Shape class. Shape Class yog lub hauv paus chav kawm. Cov chav kawm vajvoog thiab daim duab peb sab yog cov chav kawm muab los. Chav kawm Vajvoog thiab chav kawm daim duab peb sab kuj muaj cov qauv kos nrog lawv tus kheej siv. Yog li, txoj kev kos duab hauv chav kawm Shape yog overridden los ntawm cov kev kos duab ntawm cov chav kawm muab los.
Nyob rau hauv qhov kev pab cuam tseem ceeb, ib qho kev siv sib txawv s ntawm hom Shape yog tsim. Thaum lub sij hawm sau, tus compiler tsuas yog xa mus rau hauv chav kawm kos qauv. Thaum lub sijhawm ua haujlwm, kev kos duab sib txawv yuav ua tiav. Ua ntej, s yuav taw tes rau qhov khoom ntawm hom Shape. Yog li, txoj kev kos duab ntawm Shape class yog invoked. Tom qab ntawd tus s yuav taw tes rau cov khoom ntawm hom Circle, thiab nws yuav hu rau txoj kev kos ntawm lub voj voog chav kawm. Thaum kawg, s yuav taw tes rau cov khoom ntawm hom Daim duab peb sab, thiab nws yuav hu rau txoj kev kos hauv daim duab peb sab chav kawm. Cov txheej txheem hu ua nyob ntawm cov khoom. Yog li ntawd, tus kwv yog siv los daws txoj kev hu hauv Late Binding. Cov ntaub ntawv xav tau rau kev khi yog muab thaum lub sijhawm ua haujlwm, yog li kev ua kom nrawm nrawm dua piv rau kev khi thaum ntxov.
Dab tsi yog qhov zoo sib xws ntawm Early Binding thiab Late Binding?
Ob Txoj Cai Thaum Ntxov thiab Late Binding yog cuam tshuam nrog polymorphism uas yog tus ncej ntawm OOP
Dab tsi yog qhov sib txawv ntawm Kev Txiav Txim Thaum Ntxov thiab Kev Sib Tw lig?
Nkauj khiv vs lig khi |
|
Tus txheej txheem ntawm kev siv cov ntaub ntawv hauv chav kawm los daws cov txheej txheem hu uas tshwm sim ntawm lub sijhawm sib sau hu ua Early Binding. | Tus txheej txheem ntawm kev siv cov khoom los daws txoj kev hu uas tshwm sim thaum lub sijhawm khiav yog hu ua Late Binding. |
Lub Sijhawm Sib Tw | |
Early Binding tshwm sim thaum muab tso ua ke. | Late Binding tshwm sim thaum lub sijhawm ua haujlwm. |
Kev khi thaum ntxov siv cov ntaub ntawv hauv chav kawm los daws txoj kev hu. | Late Binding siv cov khoom los daws txoj kev hu. |
Synonyms | |
Kev khi thaum ntxov tseem hu ua static binding.. | Late Binding tseem hu ua dynamic binding. |
Kev tshwm sim | |
Txoj kev tshaj tawm yog sib koom ua ke siv thaum ntxov. | Txoj kev hla dhau yog sib koom ua ke siv lig khi. |
Kev nrawm nrawm | |
Kev ua kom nrawm nrawm nrawm dua thaum ntxov. | Kev ua kom nrawm qis dua hauv kev khi lig. |
Summary – Early vs Late Binding
OOP feem ntau yog siv rau kev txhim kho software. Ib tug ncej loj ntawm OOP yog polymorphism. Early Binding thiab Late Binding muaj feem xyuam rau qhov ntawd. Early Binding tshwm sim ntawm lub sijhawm sib sau thaum Late Binding tshwm sim ntawm lub sijhawm ua haujlwm. Nyob rau hauv txoj kev overloading, lub bonding tshwm sim siv thaum ntxov binding. Nyob rau hauv txoj kev overriding, lub bonding tshwm sim siv lub lig binding. Qhov sib txawv ntawm Early thiab Late Binding yog tias Early Binding siv cov ntaub ntawv hauv chav kawm los daws cov qauv hu thaum Late Binding siv cov khoom los daws txoj kev hu.