Ib qho piv txwv ntawm ib chav kawm twg sawv cev li cas?
Ib qho piv txwv ntawm ib chav kawm twg sawv cev li cas?

Video: Ib qho piv txwv ntawm ib chav kawm twg sawv cev li cas?

Video: Ib qho piv txwv ntawm ib chav kawm twg sawv cev li cas?
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim

Qhov no txhais tau tias lawv ua tsis belongs rau lub chav kawm nws tus kheej. Hloov chaw, lawv qhia tias qhov hloov pauv dab tsi thiab txoj kev yog nyob rau hauv ib yam khoom uas belongs rau qhov ntawd chav kawm . (Cov khoom no hu ua " piv txwv "ntawm chav kawm .) Yog li ntawd, piv txwv variables thiab piv txwv li yog cov ntaub ntawv thiab tus cwj pwm ntawm cov khoom.

Hais txog qhov no, qhov piv txwv ntawm ib chav kawm txhais li cas?

Hauv object-oriented programming (OOP), ib piv txwv yog ib qho tshwm sim ntawm ib yam khoom, uas muaj feem ntau thaum lub sij hawm khiav ntawm lub computer program. Qhov khoom yog ib qho piv txwv ntawm ib chav kawm , thiab tej zaum yuav hu ua a chav piv txwv los yog chav kawm khoom; instantiation yog ces hu ua kev tsim kho.

Ib sab saum toj no, piv txwv piv txwv piv txwv li dab tsi? Nyob rau hauv object-oriented programming nrog cov chav kawm, ib piv txwv variable yog a sib txawv txhais nyob rau hauv ib chav kawm (piv txwv li ib tug tswv cuab sib txawv ), uas txhua yam khoom instantiated ntawm chav kawm muaj ib daim ntawv cais, los yog piv txwv . Ib piv txwv variable zoo ib yam li chav kawm sib txawv . Variables yog khoom yam khoom paub txog nws tus kheej.

Ib sab saum toj no, dab tsi yog ib qho piv txwv?

Txoj kev piv txwv yog txoj kev uas xav tau ib yam khoom ntawm nws chav kawm yuav tsum tau tsim ua ntej nws tuaj yeem hu tau. Hu rau a piv txwv txoj kev , peb yuav tsum tsim ib qho Object ntawm chav kawm nyob rau hauv uas nws txhais.

Cov chav kawm siv dab tsi los txhais lawv tus cwj pwm?

a chav kawm piav qhia txog cov ntsiab lus ntawm cov khoom uas muaj rau nws: nws piav qhia txog cov ntaub ntawv sib sau ua ke (hu ua piv txwv hloov pauv), thiab txhais cov haujlwm (hu ua txoj hauv kev). object: Cov khoom yog qhov tseeb ntawm cov kev pab cuam, thaum lub chav kawm qhia txog qhov xwm txheej li cas yog tsim thiab ua li cas lawv coj tus cwj pwm.

Pom zoo: