Abstract Class vs Inheritance
Abstract class and Inheritance yog ob qho tseem ceeb ntawm cov khoom taw qhia cov ntsiab lus pom nyob rau hauv ntau yam khoom siv hom lus xws li Java. Cov chav kawm Abstract tuaj yeem suav tau tias yog ib qho kev paub daws teeb meem ntawm chav kawm tsis tu ncua (pob zeb), thaum Inheritance tso cai rau cov chav kawm tshiab txuas ntxiv mus rau lwm cov chav kawm. Cov chav kawm Abstract yog chav kawm uas tsis tuaj yeem pib tab sis tuaj yeem txuas ntxiv. Yog li, cov chav kawm Abstract tsuas yog muaj txiaj ntsig kom muaj yog tias cov lus programming txhawb nqa qub txeeg qub teg. Hauv Java, Cov chav kawm Abstract tau tshaj tawm siv cov ntsiab lus tsis txaus ntseeg, thaum Extends lo lus tseem ceeb yog siv rau kev txais los ntawm cov chav kawm (super).
Dab tsi yog Chav Kawm Abstract?
Feem ntau, Cov chav kawm paub daws teeb meem, tseem hu ua Abstract Base Classes (ABC), tsis tuaj yeem ua tam sim (ib qho piv txwv ntawm chav kawm ntawd tsis tuaj yeem tsim). Yog li, cov chav kawm Abstract tsuas yog muaj txiaj ntsig kom muaj yog tias cov lus programming txhawb nqa qub txeeg qub teg (muaj peev xwm los tsim cov subclasses los ntawm kev nthuav dav hauv chav kawm). Cov chav kawm Abstract feem ntau yog sawv cev rau lub tswv yim paub daws teeb los yog qhov chaw nrog ib feem lossis tsis siv. Yog li ntawd, cov chav kawm Abstract ua raws li niam txiv cov chav kawm los ntawm cov chav kawm me nyuam tau muab los kom cov menyuam kawm ntawv yuav qhia cov yam ntxwv tsis tiav ntawm cov niam txiv chav kawm thiab kev ua haujlwm tuaj yeem ntxiv los ua kom tiav lawv.
Cov chav kawm Abstract tuaj yeem muaj cov txheej txheem Abstract. Subclasses txuas ntxiv ib chav kawm paub daws teeb meem tuaj yeem ua raws li cov txheej txheem no (kuj paub) Abstract. Yog hais tias tus me nyuam chav kawm siv tag nrho cov txheej txheem Abstract, nws yog ib chav kawm tiav. Tab sis yog tias tsis yog, chav kawm me nyuam kuj dhau los ua chav kawm Abstract. Tag nrho qhov no txhais tau li cas yog tias, thaum tus programmer xaiv cov chav kawm ua Abstract, nws tau hais tias chav kawm yuav ua tsis tiav thiab nws yuav muaj cov ntsiab lus uas yuav tsum tau ua kom tiav los ntawm kev txais cov subclasses. Qhov no yog ib txoj hauv kev zoo los tsim ib daim ntawv cog lus ntawm ob tus programmers, uas ua kom yooj yim cov haujlwm hauv kev txhim kho software. Tus programmer, uas sau cov cai los ua qub txeeg qub teg, yuav tsum ua raws li txoj kev txhais raws nraim (tab sis tau kawg tuaj yeem muaj nws tus kheej siv).
Dab tsi yog Txoj Cai?
Txoj kev cuab yeej cuab tam yog ib lub tswv yim taw qhia, uas tso cai rau cov chav kawm tshiab txuas ntxiv mus rau lwm chav. Extends lo lus tseem ceeb yog siv los siv lub tswv yim ntawm qub txeeg qub teg hauv Java programming lus. Inheritance tseem ceeb muab cov cai rov siv dua los ntawm kev tso cai txuas ntxiv cov khoom thiab tus cwj pwm ntawm cov chav kawm uas twb muaj lawm los ntawm chav kawm tshiab. Thaum ib tug tshiab subclass (los yog derived class) ncua ib chav kawm super (los yog niam txiv chav kawm) uas subclass yuav tau txais tag nrho cov cwj pwm thiab cov txheej txheem ntawm cov chav kawm super. Cov subclass tuaj yeem xaiv qhov kev coj cwj pwm (muab kev ua haujlwm tshiab lossis txuas ntxiv mus rau txoj hauv kev) tau txais los ntawm niam txiv chav kawm. Feem ntau, A subclass tsis tuaj yeem txuas ntau cov chav kawm super (piv txwv li hauv Java). Yog li, koj tsis tuaj yeem siv txuas ntxiv rau ntau yam qub txeeg qub teg. Txhawm rau kom muaj ntau yam qub txeeg qub teg, koj yuav tsum siv cov interfaces.
Dab tsi yog qhov txawv ntawm Chav Kawm Abstract thiab Inheritance?
Cov chav kawm Abstract feem ntau yog sawv cev rau lub tswv yim paub daws teeb lossis ib qho chaw uas muaj ib feem lossis tsis siv. Inheritance tso cai rau cov chav kawm tshiab txuas ntxiv mus rau lwm chav. Vim tias, cov chav kawm Abstract tsis tuaj yeem ua tau sai, koj yuav tsum siv lub tswv yim ntawm kev qub txeeg qub teg los siv cov chav kawm Abstract. Txwv tsis pub, chav kawm Abstract tsis siv. Cov chav kawm Abstract tej zaum yuav muaj cov txheej txheem Abstract thiab thaum cov chav kawm txuas ntxiv, txhua txoj hauv kev (Abstract thiab pob zeb) tau txais txiaj ntsig. Cov chav kawm qub txeeg qub teg tuaj yeem ua raws li ib qho lossis tag nrho cov txheej txheem. Yog tias tag nrho cov txheej txheem Abstract tsis raug siv, chav kawm ntawd kuj dhau los ua chav kawm Abstract. Ib chav kawm tsis tuaj yeem tau txais txiaj ntsig los ntawm ntau dua ib chav kawm Abstract (qhov no tsis yog qhov zoo ntawm cov chav kawm Abstract per se, tab sis yog txwv tsis pub muaj qub txeeg qub teg).
Related posts:
Qhov Sib Txawv Ntawm Chav Kawm Abstract thiab Chav Ua Vaj Tsev
Qhov txawv ntawm Virtual thiab Abstract
Qhov txawv ntawm Chav Kawm Abstract thiab Interface
Qhov Sib Txawv Ntawm Kev Siv thiab Ntxiv
Difference between Graph and tree
Filed Hauv: Programming Tagged Nrog: ABC, abstract, Abstract Base Classes, Abstract classes, Abstract classes, Abstract keyword, Abstract method, concrete class, Extends keyword, Inheritance, Inheritance class, inherited class, Java, ntau yam qub txeeg qub teg, object oriented concepts, chav kawm tsis tu ncua, chav kawm super
About the Author: Indika
Indika, BSc. Eng, MSECE Computer Engineering, PhD. Khoos phis tawj Science, yog tus pabcuam xibfwb thiab muaj kev tshawb fawb txog kev kawm txog Bioinformatics, Computational Biology, thiab Biomedical Natural Language Processing.
Comments
-
Jason hais tias
YAug 30, 2017 at 1:25 pm
Ua tsaug rau koj piav qhia qhov txawv. Tag nrho kuv cov lus nug tau raug daws los ntawm qhov no.
Reply
-
Aus says
Lub peb hlis ntuj 10, 2019 ntawm 3: 04 pm
teb zoo tshaj plaws hauv lub vev xaib, Tus Xib Fwb tsis piav qhia dab tsi thiab tsis muaj txiaj ntsig, mono tone mf. Nov yog qhov koj piav txog cov ntsiab lus.
Reply
Tau teb Ncua tseg teb
Koj email chaw nyob yuav tsis raug luam tawm. Cov teb uas yuav tsum tau muaj yog cim
Comment
Npe
Website