YUAV UA LI CAS interface muaj cov kev tsis paub daws teeb meem?
YUAV UA LI CAS interface muaj cov kev tsis paub daws teeb meem?

Video: YUAV UA LI CAS interface muaj cov kev tsis paub daws teeb meem?

Video: YUAV UA LI CAS interface muaj cov kev tsis paub daws teeb meem?
Video: Tsis Muaj Peev Xwm Yuav Ua Li Cas 2024, Kaum ib hlis
Anonim

Cov txheej txheem interface yog los ntawm kev txhais pej xeem thiab abstract , yog li koj ua tsis tau muaj tsis muaj - abstract txoj kev hauv koj interface . Hauv Java, txheej txheem interface yog pej xeem thiab abstract los ntawm lub neej ntawd. Yog li thawj qhov kev xaiv yog kev coj tsis zoo. Point yog koj ua tau tsis siv tsis yog - abstract txoj kev sab hauv interface , vim lawv abstract los ntawm lub neej ntawd.

Tsis tas li ntawd, ib qho interface puas tuaj yeem muaj kev paub daws teeb meem?

Ib interface yog zoo li "ntshiab" abstract chav kawm. Chav kawm thiab tag nrho nws txoj kev yog abstract . Ib abstract chav kawm tuaj yeem muaj ua raws txoj kev tab sis cov chav kawm nws tus kheej tsis tuaj yeem ua sai sai (pab tau rau kev ua qub txeeg qub teg thiab ua raws li DRY). Yog tias koj siv lub Interface tom qab ntawd koj yuav tsum ua raws li cov kev cai txoj kev hauv interface.

Tsis tas li, cov chav kawm paub daws teeb meem puas muaj cov txheej txheem tsis paub meej? Yog peb tuaj yeem muaj ib chav kawm abstract tsis muaj Abstract Methods raws li ob qho tib si yog cov tswv yim ywj pheej. Tshaj tawm a chav kawm abstract txhais tias nws ua tau tsis tau instantiated ntawm nws tus kheej thiab ua tau tsuas yog sub classed. Tshaj tawm a txoj kev abstract txhais tau tias Txoj kev yuav tau txhais nyob rau hauv lub subclass.

Dhau li ntawd, peb puas tuaj yeem txhais cov txheej txheem hauv interface?

Zoo li chav kawm, ib interface tau muaj txoj kev thiab variables, tab sis cov txoj kev tshaj tawm nyob rau hauv ib interface yog los ntawm default abstract (tsuas yog txoj kev kos npe, tsis muaj lub cev). Interfaces qhia tias chav kawm twg yuav tsum ua thiab tsis ua li cas. Yog ib chav kawm siv qhov no interface , ces nws ua tau siv los txheeb cov khoom sau.

Puas yog txhua txoj hauv kev hauv ib qho interface yuav tsum tau ua?

Yog, nws yog qhov yuav tsum tau ua siv tag nrho tus txoj kev nyob rau hauv ib chav kawm uas siv ib qho interface tshwj tsis yog thiab kom txog rau thaum chav kawm ntawd yog chav kawm Abstract. Koj muaj ob txoj kev xaiv: - siv txhua txoj kev xav tau los ntawm interface los yog - tshaj tawm qhov ploj lawm txoj kev abstract hauv koj chav kawm.

Pom zoo: