SOLID ndeapi iwo mashanu nheyo dzechinhu chakatemerwa chirongwa

Solid solid geometric manhamba
kudzidza
1

SOLID chidimbu, ichitaura nezvezvikamu zvishanu zvechinangwa-chakatarisana dhizaini (OOD kana OOP). Aya ndiwo marongero anogona kugadzirwa nevanogadzira kugadzira software iri nyore kubata, kuchengetedza uye kuwedzera. Kunzwisisa pfungwa idzi kunozokuita iwe unogadzira zvirinani uye kukubatsira kudzivirira matambudziko ekugadzirisa software. Zvinorevei kuva akanaka programmer?

Chero ani ane ruzivo mune software programming anotonga software kodhi yakanyorwa nevamwe, vachishandisa marongero eparamende zvinoenderana nebasa ravo.

Pamusoro pebasa rangu rehunyanzvi, ini ndinoziva vazhinji vanogadzira, uye ndaona zviuru zvemitsetse yekodhi uye pandinoda kuongorora hunyanzvi hwekuvandudza ini ndinotarisa pazvinhu zviviri:

  • Nyore mukuverenga kodhi;
  • Ingangoita sei kodhi yavo yekushanda uye kushanduka nekufamba kwenguva.

Neraki, pane zvimwe zvakakosha kana misimboti inoita kuti zvive nyore kuve nani pakukodha.

chidimbu SOLID chinomirira:
S: musimboti webasa rimwe chete
O: yakavhurika-yakavharwa musimboti
L: Liskov kutsiva musimboti
I: Musimboti wekuparadzanisa interface
D: Zvingakubatsira kuti Inversion pamusoro Dependencies

Ngatitange nekutsvagisa yekutanga SOLID musimboti, kureva iyo

Imwe Yekuremerwa Musimboti

Kirasi (kana module) inofanirwa kuve nechikonzero chimwe chete chekuchinja, kushanduka.

Pfungwa yacho pachayo yakapusa, asi kuti uwane izvi zvakapfava nzira yekumisikidza inogona kunge yakaoma zvikuru. Kirasi inofanirwa kuve nechikonzero chimwe chete chekuchinja.

Asi nei? 

Sei zvichikosha kuva nechikonzero chimwe chete chekuchinja?

Semuenzaniso, kana paine zvikonzero zviviri zvakasiyana zvekuchinja, zvinofungidzirwa kuti zvikwata zviviri zvakasiyana zvinogona kushanda kodhi imwechete nekuda kwezvikonzero zviviri zvakasiyana. Mumwe nemumwe achafanirwa kuita yavo yega mhinduro, iyo mune yekunyorwa mutauro (senge C ++, C # kana Java), zvinogona kutungamira kumamojuru asingawirirane nemamwe zvikwata kana zvimwe zvikamu zvekushandisa.

Mumwe muenzaniso, kana urikushandisa mutauro wakadudzirwa, ungatofanira kuyedzazve kirasi imwechete kana module yezvikonzero zvakasiyana. Izvi zvinoreva basa rakawanda, nguva uye nesimba rekudzora mhando.

Kuziva iyo yega ficha yekirasi kana module inofanirwa kuve nayo yakanyanya kuomarara pane kungotarisa pane yekutarisa kuti umhanye bvunzo. 

Asi ngatiedzei kufunga kubva pane shoma tekinoroji yekutarisa, ndokuti, ngatiedzei kuongorora mushandisi wekirasi yedu kana module, ndiye anozoishandisa. Chinhu chakakosha chatinofanira kugara tichifunga, inyaya yekuti vashandisi vechishandiso kana sisitimu yatinokudziridza vanoshumirwa neimwe module ichave avo vanokumbira kuchinjirwa kwairi. Ivo vakashumirwa vanokumbira kuti vachinje kirasi kana module. 

Mimwe mienzaniso yemamojuru uye mashandisiro avo:

  • Maintenance module: mushandisi anoumbwa nevatungamiriri ve database uye mapurani esoftware.
  • Kushuma module: mushandisi anoumbwa nevashandi vemuhofisi, maakaundendi uye kugadzirwa.
  • Kubhadhara kuverenga module yemubhadharo manejimendi system: vashandisi vanogona kusanganisira magweta, mamaneja uye maakaunzi.
  • Chinyorwa chekutsvaga module yemaraibhurari manejimendi system: mushandisi anogona kumiririrwa neraibhurari kana nevashanyi nevatengi vetaraibhurari pachayo.

Saka kana danho rekutanga riri kutsvaga vatambi kana mutambi ane chinzvimbo chemutauriri nemo module, kubatanidza vanhu neese mabasa kungave kwakaoma. Mukambani diki, munhu mumwe anogona kutamba akawanda mabasa mukambani hombe panogona kuve nevanhu vakawanda vane rimwe basa. 

Zvinotaridza sezvine musoro kuona mabasa, kwete vanhu kana vashandisi.

Naizvozvo:

  • mushandisi weiyo software system anotsanangura zvikonzero zvekuchinja;
  • basa imhuri yemabasa inogutsa zvido zvemumwe mutambi, ndokuti, weye mushandisi system;
  • vatambi, mushandisi anova sosi yeshanduko yemhuri yeanoshanda ayo anofanira kugutsa chinodiwa chemushandisi;
  • shanduko yezvinodiwa nemushandisi, inotyaira shanduko yekushanda;

SOLID misimboti

Ngatione mimwe mienzaniso

Ngatitii tine bhuku reBhuku rinovhara pfungwa yebhuku uye mashandiro aro.

Kirasi Bhuku {

    basa tora () {

        dzoka “Bhuku Huru”;

    }

    basa GetAuthor () {

        dzoka "Alessandro Baricco";

    }

    shanda rinotevera peji () {

        // rinotevera peji

    }

    shanda printCurrent Peji () {

        echo "zvirimo peji razvino";

    }

}

Iri kirasi rakajairika. Tine bhuku, uye kirasi inogona kutipa zita racho, vanogona kutipa munyori, uye vanogona kuenderera mberi. Chekupedzisira, zvakare inokwanisa kudhinda peji razvino pachiratidziri. 

Nekudaro, pane dambudziko diki. 

Kufunga nezvevatambi vanobatanidzwa mukutungamira kweBhuku chinhu, vangave vanaani? 

Tinogona kufunga zviri nyore nezvevatambi vaviri vakasiyana pano: Book manejimendi (seiyo anozvibatae Dhata yekutumira mashini

Saka isu tine vatambi vaviri vakasiyana kwazvo vari kudyidzana nekirasi.

Muchidimbu kirasi iyi inoita musanganiswa pakati:

  • pfungwa yebhizinesi ne 
  • mharidzo 

ichi chingave chinetso nekuti chinotyora chirevo chimwechete chemutoro (SRP). 

Tinogona sei kuchinja, isu tingaite sei kuvandudza kodhi iyi kuti tiremekedze chirevo cheumwe mutoro?

Tarisa uone kodhi inotevera:

Kirasi Bhuku {

    basa tora () {

        dzoka "Oceano Mare";

    }

    basa GetAuthor () {

        dzoka "Alessandro Baricco";

    }

    basa shandura peji () {

        // rinotevera peji

    }

    shanda getCurrentPage () {

        echo "zvirimo peji razvino";

    }

}

inowanikwa Printer {

    basa printPage ($ peji);

}

kirasi StampaLibro inoshandisa Printer {

    basa printPages ($ peji) {

        echo $ peji;

    }

}

 

kirasi HtmlPrinter inoshandisa Printer {

    basa printPages ($ peji) {

        echo ' '. $ peji. ' ';

    }

}

Uyu muenzaniso wakapusa unoratidza maitiro ekuparadzanisa mharidzo kubva kune bhizinesi logic, uye mukuteerera SRP inopa zvakanaka kwazvo mukuchinjika kweprojekiti yedu.

Ngatitarisei mumwe muenzaniso:

Muenzaniso wakafanana neiri pamusoro apa kana chinhu chichigona kuzvichengeta nekuzvitora kubva pachiratidziro.

Kirasi Bhuku {

    basa tora () {

        dzoka "Oceano Mare";

    }

    basa GetAuthor () {

        dzoka "Alessandro Baricco";

    }

    basa shandura peji () {

        // rinotevera peji

    }

    shanda getCurrentPage () {

        dzosera "zvirimo peji razvino";

    }

    basa chengetedza () {

        $ filename = '/ zvinyorwa /'. $ iyi-> GetTitolo (). '-'. $ this-> getAuthor ();

        file_put_contents ($ filename, serialize ($ this));

    }

}

Sapakutanga, pano zvakare tinogona kuziva vatambi vakasiyana vakaita Book manejimendi (seiyo anozvibatae kutsungirira. Pese patinoda kushandura nzira yatinoenda kubva peji kuenda kupeji, tinofanirwa kushandura kirasi iyi. Tinogona kuve nezvikonzero zvinoverengeka zvekuchinja.

Kirasi Bhuku {

    basa tora () {

        dzoka "Oceano Mare";

    }

    basa GetAuthor () {

        dzoka "Alessandro Baricco";

    }

    basa shandura peji () {

        // rinotevera peji

    }

    shanda getCurrentPage () {

        dzosera "zvirimo peji razvino";

    }

}

kirasi SimpleFilePersistence {

    basa chengetedza (Bhuka $ bhuku) {

        $ filename = '/ zvinyorwa /'. $ bhuku-> getTitle (). '-'. $ bhuku-> getAuthor ();

        file_put_contents ($ filename, serialize ($ book));

    }

}

Kufambisa basa rekushingirira kune rimwe kirasi kuchanyatso kupatsanura mabasa uye tichava takasununguka kuchinjana nzira dzekushingirira tisingakanganise kirasi yedu yeBhuku. Semuenzaniso, kushandisa DhatabhesiPersistence kirasi kungave kushoma, uye pfungwa yedu yebhizinesi yakavakirwa pamabasa ebhuku haizo shanduke.

Enderera kuverenga mutemo wechipiri Vhura / Yakavharwa ->

1 rondedzero

Siya mhinduro

Yako email kero haisi kuzobudiswa. Minda yekumanikidza inomakwa *

liskov musimboti
kudzidza
Nheyo yeLiskov Chinzvimbo, chechitatu SOLID musimboti

Makirasi evana haafanire kukanganisa kana kushandura mhando tsananguro dzekirasi yemubereki. Pfungwa yemutemo uyu yakaunzwa naBarbara Liskov mune yakakosha yemusangano we1987 uye ikazoburitswa muchinyorwa pamwechete naJannette Wing muna1994.Dudziro yavo yekutanga…

google kushambadzira maitiro
kudzidza
Mashandisiro ekushandisa Google Maitiro ekushambadzira-chaiwo-nguva

Rimwe rematambudziko akakura akasangana nemakambani mu2020 yaive yekunzwisisa kuti zvikamu zvechigadzirwa zvinosanganisa bhizinesi ravo: kutaura zvazviri, mazhinji emakambani emaindasitiri akatambura zvakakomba zvichiita kuti zvikone kupinda mumakambani, kunyanya semutambi mutsva. Zvishoma kwazvo zvikamu zvekugadzira ...

bhizinesi njere zano
nzira
Maitiro ekubudirira kweBusiness Intelligence

Kuvaka zano rakabudirira reBusiness Intelligence yako kunotanga nemaonero echokwadi ezvinangwa. Isu tinoona pazasi mamwe akakosha mapoinzi. Kuongorora mamiriro azvino chingave chikanganiso chakakura kurerutsa chikamu ichi. Kuongorora mamiriro azvino zvinoreva kuongorora maitiro, zvimiro ...