Thaum twg koj yuav tsum ua ib chav kawm abstract?
Thaum twg koj yuav tsum ua ib chav kawm abstract?

Video: Thaum twg koj yuav tsum ua ib chav kawm abstract?

Video: Thaum twg koj yuav tsum ua ib chav kawm abstract?
Video: thaum twm mam tseg txoj kev haus npias tsom xyooj nkauj tawm tshiab 2023 2024, Hlis ntuj nqeg
Anonim

6 Teb. Feem ntau, a chav kawm yuav tsum ua abstract thaum koj tsis muaj laj thawj kiag li tsim ib qho piv txwv ntawm qhov ntawd chav kawm . Piv txwv li, xav tias koj muaj Shape chav kawm uas yog superclass ntawm daim duab peb sab, Square, Vajvoog, thiab lwm yam.

Tsis tas li ntawd, vim li cas koj thiaj li tshaj tawm cov chav kawm raws li paub daws teeb meem?

Txheej txheem cej luam. Ib ntawm cov ntsiab lus tseem ceeb hauv OOP yog qhov chav kawm abstract . Cov chav kawm Abstract tsis tuaj yeem instantiated thiab tsim los ua subclassed. Lawv tau siv los muab qee qhov kev ua haujlwm zoo sib xws thoob plaws cov txheej txheem cuam tshuam chav kawm thaum tseem tso cai rau kev siv cov txheej txheem.

Tom qab ntawd, lo lus nug yog, thaum twg koj yuav tsum siv chav kawm abstract vs interface? Cov lus teb luv luv: Ib chav kawm abstract tso cai koj to tsim functionality uas subclasses siv tau los yog override. Ib interface tsuas tso cai koj to txhais functionality, tsis siv nws. Thiab hos a chav kawm tuaj yeem txuas ntxiv ib chav kawm abstract , nws ua tau coj qhov zoo ntawm ntau yam interfaces.

Raws li, dab tsi tuaj yeem muab tso rau hauv chav kawm paub daws teeb meem?

Ib chav kawm abstract yog a chav kawm uas tsis tuaj yeem instantiated. Ib chav kawm abstract yog siv los ntawm tsim ib tug inheriting subclass uas ua tau ua instantiated. Ib chav kawm abstract ua ob peb yam rau kev txais cov subclass: Txhais cov txheej txheem uas tau yuav siv los ntawm cov khoom qub txeeg qub teg.

Yuav ua li cas koj tsim ib chav kawm abstract?

Rau tsim ib chav kawm abstract , tsuas yog siv cov abstract lo lus tseem ceeb ua ntej chav kawm keyword, hauv chav kawm tshaj tawm. Koj tuaj yeem saib qhov ntawd tsuas yog abstract cov txheej txheem cov neeg ua haujlwm chav kawm zoo ib yam li qub chav kawm hauv Java. Cov chav kawm yog tam sim no abstract , tab sis nws tseem muaj peb lub teb, xya txoj kev, thiab ib tus tsim.

Pom zoo: