Koj ua li cas thaum ntxov thiab tub nkeeg pib ntawm ib qho khoom?
Koj ua li cas thaum ntxov thiab tub nkeeg pib ntawm ib qho khoom?

Video: Koj ua li cas thaum ntxov thiab tub nkeeg pib ntawm ib qho khoom?

Video: Koj ua li cas thaum ntxov thiab tub nkeeg pib ntawm ib qho khoom?
Video: Tswv Yexus lub neej thaum pib txug thaum xaus 2024, Hlis ntuj nqeg
Anonim

4 Teb. Zoo Lazy pib txhais tau tias koj ua tsis yog pib cov khoom mus txog rau thawj zaug lawv yog siv. Thaum ntxov pib tsuas yog rov qab, koj pib a singleton upfront thaum lub sijhawm thauj khoom hauv chav kawm. Nyob ntawd yog txoj kev ua thaum ntxov pib , ib tug yog los ntawm kev tshaj tawm koj singleton li static.

Tom qab ntawd, tub nkeeg pib txhais li cas?

Hauv computer programming, tub nkeeg pib yog lub tactic ntawm ncua lub creation ntawm ib yam khoom, xam tus nqi, los yog lwm yam kim txheej txheem mus txog rau thaum thawj zaug nws yog xav tau. Nws yog ib hom tub nkeeg kev ntsuam xyuas uas hais tshwj xeeb rau cov kev xav ntawm cov khoom lossis lwm yam kev pabcuam.

Tsis tas li, thaum twg koj yuav tsum siv Lazy T hom? 7 Teb. Koj feem ntau siv nws thaum koj xav rau instantiate ib yam dab tsi thawj zaug nws ua tau siv . Qhov no ncua tus nqi ntawm kev tsim nws txog thaum / thaum nws xav tau es tsis txhob ua rau tus nqi ib txwm muaj. Feem ntau qhov no yog qhov zoo dua thaum qhov khoom yuav lossis tsis yog siv thiab tus nqi ntawm kev tsim nws yog qhov tsis tseem ceeb.

Hauv qhov no, dab tsi yog tub nkeeg thiab xav pib pib?

Lazy pib yog cov txheej txheem peb txwv cov khoom tsim kom txog thaum nws tsim los ntawm daim ntawv thov code. Hauv lwm txoj kev kev xav pib tsim cov khoom ua ntej thiab tsuas yog tom qab pib daim ntawv thov lossis module. Qhov no yuav pab tau yog tias cov khoom yuav tsum tau ua thiab hauv txhua qhov kev ua haujlwm.

Koj puas tuaj yeem siv tus qauv singleton siv tub nkeeg pib?

Lazy Initialization Lazy pib txoj kev mus siv Singleton qauv tsim qhov piv txwv hauv txoj kev nkag mus thoob ntiaj teb. Nws yuav rhuav tshem cov singleton qauv thiab ob txoj xov yuav tau qhov sib txawv ntawm cov singleton chav kawm.

Pom zoo: