Imodeli-yokujonga-isilawuli (i-MVC) yoyilo

NguNeal Goldstein, uDave Wilson

Inkqubo-sikhokelo ye-iOS zezi ejolise kwinto . Indlela elula yokuqonda ukuba oko kuthetha ukuthini ukucinga ngeqela elisebenza eofisini. Umsebenzi ekufuneka wenziwe wahlulwe wabelwa amalungu eqela ngalinye (kule meko, izinto). Ilungu ngalinye leqela linomsebenzi kwaye lisebenza namanye amalungu eqela ukwenza izinto.



Ngaphezu koko, ilungu leqela elilungileyo alikhathali nokuba amanye amalungu awenza njani umsebenzi wawo, kodwa kukuba awenza ngokwecandelo ekuvunyelwene ngalo ngabasebenzi. Kwangokunjalo, into ekwinkqubo ejolise kwinto ikhathalela ishishini layo kwaye ayikhathali nokuba yeyiphi into ekwigumbi elisenyongweni eliyenzayo, ukuba nje izakwenza into ekufanele ukuba iyenzile xa iceliwe.



Inkqubo ejolise kwinto yaqala yaphuhliswa ukwenza ikhowudi ukuba igcineke ngakumbi, iphinde isebenze, inokwandiswa kwaye iqondakale ngokufaka konke ukusebenza emva konxibelelwano oluchazwe kakuhle. Iinkcukacha zokwenyani zento ethile esebenza (kunye nedatha yayo) zifihliwe, ezenza ukuba ukutshintsha nokwandisa usetyenziso kube lula.

Kukhulu-ukuza kuthi ga ngoku-kodwa umbuzo onobuzaza usabaphatha kakubi aba dwelisi benkqubo:



Ngokuchanekileyo ugqibe njani kwizinto kwaye yintoni nganye eyenzayo?

Ngamanye amaxesha impendulo yalo mbuzo ilula kakhulu-sebenzisa nje ilizwe lokwenyani njengemodeli. Inkqubo yeTripTrip, umzekelo, ezinye zeeklasi zezinto eziyimodeli zeziUhambo,Iziganeko,Indawo oya kuyo, kwaye nangokunjalo. Kodwa xa kufikwa kwinkqubo yolwakhiwo oluqhelekileyo, njani yenza Ugqiba ukuba zithini izinto? Isenokungabonakali loo nto.

Ipateni ye-MVC yindlela emiselwe kakuhle yokwenza imisebenzi yeqela kwizinto. Umahluko wawo ubukho ubuncinci ukusukela kwiintsuku zokuqala zeSmallTalk, enye yeelwimi zokuqala ezijolise kwinto. I-MVC yipateni ekumgangatho ophezulu-ijongana nokwakhiwa kwesicelo kwaye ihlela izinto ngokwendima ngokubanzi abayidlalayo kwisicelo, endaweni yokugrogrisa kwizinto ezithile.



Ipateni ye-MVC idala, ngokungathi kunjalo, indalo encinci yesicelo, enabantu abaneentlobo ezintathu zezinto. Ikwachaza iindima noxanduva kuzo zontathu iintlobo zezinto kwaye ichaza indlela ekufanele ukuba basebenzisane ngayo. Ukwenza izinto zibambeke ngakumbi (Oko kukuthi, ukugcina intloko yakho ingadubuli), cinga i-TV enkulu enkulu, entle, engama-intshi angama-60. Nanku umxholo:

  • Izinto zemodeli: Ezi zinto ngokudibeneyo zenza umxholo wenjini yakho. Ziqulathe idatha yolu setyenziso kunye nengcinga- yokwenza usetyenziso lwakho lube ngaphezulu kobuso obuhle.

    Ungacinga nge imodeli (enokuthi ibe yinto enye okanye ezininzi ezisebenzisanayo) njengenkqubo ethile kamabonakude, leyo, ngokuphandle, ayinikezi i-hoot malunga nokuba iseti yeTV iboniswa ngantoni.

    Ngapha koko, imodeli akufuneki inike ihoot. Nangona inedatha yayo, ayifanelanga ukuba ibe nonxibelelwano kunxibelelwano lomsebenzisi kwaye kufuneka ingonwabisi into eyenziweyo ngedatha yayo.

    iziphumo ebezingalindelwanga jet
  • Jonga izinto: Ezi zinto zibonisa izinto kwiscreen kwaye ziphendula kwizenzo zomsebenzisi. Intle kakhulu into onokuyibona luhlobo lwento yokujonga- iwindow kunye nolawulo lonke, umzekelo.

    Izimvo zakho ziyayazi indlela yokubonisa ulwazi abalufumanayo kwinto yemodeli kunye nendlela yokufumana igalelo kumsebenzisi onokufuna imodeli. Kodwa umbono ngokwawo awufanele wazi nto malunga nemodeli. Inokuphatha isicelo ukubonisa imicimbi ethile, kodwa ayizikhathazi ngokuba kuthetha ntoni na eso sicelo.

    Ungacinga nge umbono Njengesikrini sikamabonwakude esingakhathaliyo ngenkqubo esiyibonisayo okanye leliphi ijelo osandula ukulikhetha.

    Inkqubo ye-UIKitIsakhelo sibonelela ngeendlela ezahlukeneyo zokujonga, njengoko ufumanisa kwicandelo elilandelayo.

    Ukuba umbono awazi nto malunga nemodeli, kwaye imodeli ayazi nto malunga nembono, ufumana njani idatha kunye nezinye izaziso zokudlula zisuka kwenye ziye kwenye? Ukuqalisa le ncoko (Umzekelo: Ndisandula ukuvuselela idatha yam. Jonga: Hei, ndinike into yokubonisa, umzekelo), ufuna into yesithathu kwi-MVC triumvirate, isilawuli.

  • Izinto zolawulo: Ezi zinto zidibanisa izinto zembono yesicelo kwizinto zayo zemodeli. Banikezela ngezinto zokujonga kunye nezinto abafuna ukuzibonisa (ukuyifumana kwimodeli) kwaye babonelele ngemodeli ngokufaka komsebenzisi kwimbono.

    Ungacinga nge umlawuli njengesekethe etsala umboniso wentambo kwaye emva koko uyithumele kwiscreen okanye ucele umboniso othile wentlawulo-nganye.

Uyilo lwesicelo esisiseko lubonakala njengoMzobo 4-8.

Inkqubo yoyilo loyilo olusisiseko.

iziphumo ebezingalindelekanga zecyclobenzaprine

Xa ucinga ngesicelo sakho ngokwemodeli, ukujonga, kunye nezinto zolawulo, iifayile zeUIKitsikhokelo siqala ukwenza intsingiselo. Ukuqonda isakhelo ngale ndlela kukwaqala nokuphakamisa inkungu exhonywe ngaphezulu kwento yokwenza ubuncinci bokuziphatha okuthe ngqo kwindlela yokuziphatha.

Ngaphambi kokuba ungene kwesi sihloko, nangona kunjalo, kuya kufuneka wazi okungakumbi malunga neeklasi ezithiUIKitibonelela, kuba ngala makhwenkwe oza kuwenza umsebenzi wokumilisela ipatheni yoyilo lwe-MVC- iiklasi zeewindows, iiklasi zokujonga, kunye nokujonga iiklasi zolawulo.

KwiNjongo-C, iiklasi zibandakanya izinto eziguquguqukayo, iipropathi, kunye neendlela (ezinokufikelela kumzekelo weklasi). Iiklasi zimalunga neefayile kwiprojekthi yakho enekhowudi. Iiklasi zinjalo iintlobo kwinkqubo yakho.

Izinto, kwelinye icala, zibakhona ngexesha lokubaleka kwaye zikhona iimeko yeklasi. Unokucinga ngeklasi njengeplani yokwakha into yolo hlobo.