Software design pattern

Ebunjiniyela be-software, ubunjiniyela, iphethini yokwakheka kwesoftware iyisisombululo esijwayelekile, esisebenzisekayo senkinga evame ukwenzeka ngaphakathi komongo inikezwe ekwakhiweni kwesoftware. Akuyona iphethini eqediwe engaguqulwa ngqo ibe ngumthombo noma ikhodi yomshini . Esikhundleni salokho, yincazelo noma isifanekiso sendlela yokuxazulula inkinga engasetshenziswa ezimeni eziningi ezihlukile. Amaphethini wokuqamba enza izinto ezihlelekile okuhlelekile ongazisebenzisa umxazululi ukuxazulula izinkinga ezivamile lapho kuklanywa isakhiwo noma uhlelo.

Amaphethini wokuklanywa okwenzelwe izinto ngokuvamile akhombisa ubudlelwane nokuxhumana phakathi kwamakilasi noma izinto, ngaphandle kokucacisa amakilasi wokugcina wesicelo noma izinto ezibandakanyekile. Amaphethini asho ukuthi isimo esingaguquki angahle afakelwe izilimi ezisebenzayo, amanye amaphethini angahunyushwa ngokungadingekile ngezilimi ezakhekile ukusekela ukuxazulula inkinga abazama ukuyixazulula, futhi amaphethini aqondiswe entweni awafaneleki ezintweni ezingahambisani nezilwimi zezinto ezenzelwene (Object-oriented)

Amaphethini wokuqamba angabukwa njengendlela ehlelekile yohlelo lokusebenza lwekhompyutha phakathi kwamazinga we- paradigm yohlelo kanye ne- algorithm yekhonkrithi.
Umlando

Amaphethini aqala njengomqondo wokwakha ngu -Christopher Alexander ekuqaleni konyaka we-1966 (cf "Isibonelo Semikhonto," JOURNAL OF AIP, Septhemba, 1966, Vol. 32, No. 3, iphe. 273-278). Ngo-1987, uKent Beck noWard Cunningham baqala ukuzama ngomqondo wokusebenzisa amaphethini ezinhlelweni - ngokukhethekile amaphethini ezilimi - futhi bethula imiphumela yabo engqungqutheleni ye- OOPSLA ngalowo nyaka. Eminyakeni elandelayo, u-Beck, uCunningham nabanye balandela lo msebenzi.

Amaphethini okuklama athola ukuthandwa kusayensi yamakhompiyutha ngemuva kokuba incwadi Design Designs: Elements of Reusable Object-Oriented Software yashicilelwa ngonyaka we-1994 ngababizwa nge- "Gang of Four" (Gamma et al.), Esivame ukufushaniswa ngokuthi "GoF". Ngawo lowo nyaka, kwaqhutshwa inkomfa yokuqala yezilimi ezihleliwe, futhi ngonyaka olandelayo kwasungulwa iPortland Pattern Repository ukuze kube yimibhalo yamaphethini wokuqamba. Isilinganiso sethemu sihlala siyindaba yokuphikisana. Izincwadi eziphawuleka kunhlobo lwephethini yoyilo zifaka:

*
*
*
*
*
*
*
*

Yize amakhethini wokuqamba esetshenziswe isikhathi eside, ukwenziwa ngokusemthethweni komqondo wamaphethini wokuqamba kwehle iminyaka eminingi.
Ukwenza

Amaphethini wokuqamba angasheshisa inqubo yokuthuthuka ngokunikeza ubuhlakani bokuvivinya obufakazelwe. Idizayini ephumelelayo yesoftware idinga ukucubungula izingqinamba ezingeke zibonakale kuze kamuva ekuqalisweni. Ikhodi esanda kubhalwa phansi ingahlala iba nezinkinga ezicashile ezithathe isikhathi ukuthi zitholwe, izingqinamba kwesinye isikhathi ezingadala izinkinga ezinkulu ngokuhamba kwesikhathi. Ukuphinda usebenzise amaphethini wokuqamba kusiza ukuvikela izindaba ezinjalo ezicashile , futhi kuthuthukisa ukufundwa kwekhodi kwenzelwa abakhodi nabaklami abajwayele amaphethini.

Ukuze uzuze ukuguquguquka, amaphethini wokuqamba avame ukwethula amazinga ongezekile we- indirection, kwezinye izimo angaphikisana nemiklamo evelayo futhi alimaze ukusebenza kwesicelo.

Ngokwencazelo, iphethini kufanele ihlelwe kabusha ohlelweni ngalunye olusebenzisayo. Njengoba abanye ababhali bebona lokhu njengesinyathelo esibuyela emuva ekusebenzeni kabusha kwesoftware njengoba kunikezwe izakhi, abacwaningi basebenze ukuguqula amaphethini abe yizakhi. UMeyer no-Arnout bakwazile ukuhlinzeka ngezakhi eziphelele noma ngokwengxenye zezingxenye ezimbili kwezintathu zamaphethini abazama ngayo.

Amasu wokuqamba amasoftware kunzima ukuwasebenzisa ebangeni lezinkinga ezibanzi. Amaphethini wokuqamba anikezela ngezixazululo ezijwayelekile, ezibhalwe ngefomethi engadingi imininingwane eboshelwe enkingeni ethile.
Isakhiwo

Amaphethini wokuqamba akhiwa izigaba eziningana (bona § Imibhalo engezansi). Okuthakazelisa kakhulu yizigaba zoBumbano, Ababambiqhaza kanye nezigaba Zokusebenzisana. Lezi zingxenye zichaza motif design : a prototypical micro-architecture ukuthi onjiniyela bakopisha futhi bazivumelanise nemiklamo yabo ethile ukuxazulula inkinga esetshenziswayo echazwe yiphethini yokuqamba. Isakhiwo esincanyana senhlanganyela seqoqo lezindawo zohlelo (isib, amakilasi, izindlela ...) kanye nobudlelwano bawo. Abathuthukisi basebenzisa iphethini lokuklama ngokwazisa kumiklamo yabo le-prototypical micro-architecture, okusho ukuthi izakhiwo ezincane ezakhiweni zazo zizoba nesakhiwo nenhlangano efana ne-design motif ekhethiwe.
Amaphethini akhethekile wesizinda

Kwenziwe futhi imizamo yokuhlanganisa amaphethini wokuqamba ezizindeni ezithile, kufaka phakathi ukusetshenziswa kwamaphethini wokuqamba akhona kanye namaphethini wokuqamba wesizinda esithile. Izibonelo zifaka amaphethini esakhiwo sokusebenziseka komsebenzisi, ukubonwa kolwazi, idizayini evikelekile, "ukusebenziseka okuphephile", ukwakhiwa kwewebhu nokuklama imodeli yebhizinisi.

Izilimi zonyaka zeKhethini Yezinhlelo Zokuhlela zifaka izibonelo eziningi zamaphethini akhethekile wesizinda.
Ukuhlukaniswa nohlu

Amaphethini wemiklamo ahlukaniswe ngezigaba ezi-3 ezisuselwa kuhlobo lwenkinga azixazululelayo. Amaphethini wokudala anika amandla okwenza izinto ngokusekelwe indlela edingekayo nangendlela elawulwayo. Amaphethini ezakhiwo akhuluma ngokuhlela amakilasi ahlukene nezinto zokwakha izakhiwo ezinkulu nokunikeza ukusebenza okusha. Ekugcineni, izindlela zokuziphatha zimayelana nokuhlonza amaphethini wokuxhumana ajwayelekile phakathi kwezinto futhi aqaphele lamaphethini.
Amaphethini wokudala
Amaphethini ezakhiwo
Amaphethini wokuziphatha
Imibhalo

Imibhalo yephethini lokuklama ichaza umongo lapho iphethini isetshenziswa khona, amandla ngaphakathi komongo iphethini elifuna ukuwaxazulula, kanye nekhambi eliphakanyisiwe. Akukho fomethi eyodwa, ejwayelekile yamaphethini wokuklama. Esikhundleni salokho, izinhlobo ezahlukahlukene zisetshenziswe ngababhali bephethini abahlukile. Kodwa-ke, ngokusho kukaMartin Fowler, izinhlobo ezithile zamaphethini ziye zaziwa kakhulu kunabanye, futhi ngenxa yalokho zaba ngamaphuzu okuqala ajwayelekile emizamo emisha yokubhala iphethini. Isibonelo esisodwa sefomethi yemibhalo evame ukusetshenziswa yileso esisetshenziswa u- Erich Gamma, uRichard Helm, uRalph Johnson, noJohn Vlissides encwadini yabo Designamps . Inezingxenye ezilandelayo:

* Igama Lephethini Nokwehlukanisa: Igama elichazayo nelingafani elisiza ekuboneni nasekubhekiseleni kuphethini.
* Inhloso: Ukuchazwa kwenhloso ngemuva kwephethini nesizathu sokuyisebenzisa.
* Yaziwa Futhi ngokuthi: Amanye amagama wephethini.
* Ukugqugquzela (Amandla): Isimo esinezinkinga kanye nomongo lapho leli phethini lingasetshenziswa khona.
* Ukusebenza: Izimo lapho le ndlela isetshenziswa khona; umongo wephethini.
* Ukwakheka: Ukuboniswa okucacisayo kwephethini. Imidwebo yekilasi kanye nemidwebo yekusebenza ingasebenziselwa lenjongo.
* Ababambiqhaza: Uhlu lwamakilasi nezinto ezisetshenziswe kuphethini nezindima zawo ekwakhiweni.
* Ukusebenzisana: Incazelo yokuthi amakilasi nezinto ezisetshenziswe kuphethini zisebenzisana kanjani.
* Imiphumela: Incazelo yemiphumela, imiphumela emibi, nokuhweba okukhohlakele okubangelwa kusetshenziswa iphethini.
* Ukuqaliswa: Ukuchazwa kokusetshenziswa kwephethini; ingxenye yesisombululo sephathini.
* Ikhodi Eyisibonelo: Umzekeliso wendlela iphethini elingasetshenziswa ngayo olimini lwezinhlelo.
* Ukusetshenziswa okwaziwayo: Izibonelo zokusetshenziswa kwangempela kwephethini.
* Amaphethini ahlobene: Amanye amaphethini anobuhlobo obuthile nephethini; ukuxoxa ngomehluko phakathi kwephethini namaphethini afanayo.
Ukugxekwa

Kuqashelwe ukuthi amaphethini wokuqamba angaba nje uphawu lokuthi ezinye izici zishoda ngolimi olunikeziwe lwezinhlelo ( iJava noma i- C ++ ngokwesibonelo). UPeter Norvig ukhombisa ukuthi amaphethini ayi-16 kwayi -23 asencwadini ye- Design Patterns (ebhekiswe kakhulu ku-C ++) ayenziwa lula noma aqedwe (ngosizo oluqondile lolimi) eLisp noma iDylan . Ukubukwa okuhlobene nakho kwenziwa nguHannemann noKiczales abasebenzise amaphethini amaningi wokuqamba angama-23 besebenzisa ulimi olususelwa kuzinhlelo (AspectJ) futhi bakhombisa ukuthi ukuncika kwezinga lekhodi kususwe ekusetshenzisweni kwamaphethini wokuqamba we-17 kwayi-23 nokuthi isisekelo-esigxile izinhlelo zingenza lula ukwenziwa kwamaphethini wokuqamba. Bheka futhi nendatshana kaPaul Graham ethi "Revenge of the Nerds".

Ukusetshenziswa okungafanele kwamaphethini kungandisa ukuxaka okungadingekile.