Has-a

From Wikipedia
Jump to navigation Jump to search

Ngokwe mininingwane ye-design, izinhlelo zezinto-zamakhasimende kanye nomklamo (bheka into ngamakhasimende Uhlelo izakhiwo ), has-a (has_a noma has a) kuyinto yokwakha ubuhlobo lapho enye into (owayevame ukubizwa ngokuthi into elimiswe, noma ingxenye / abamelwe / ilungu into) " kungokwalabo "(kuyinto ingxenye noma ilungu ) enye into (ngokuthi uhlobo esiyinhlanganisela), futhi siziphathe ngokuvumelana nemithetho kobunikazi. Ngamagama alula, has-ubuhlobo e into ibizwa ngokuthi ensimini ilungu into. Multiple has-a ubudlelwano kuzohlanganisa ukwakha isigaba sabaphathi sebuniyo.

Lokhu kumele ziqhathaniswa i luyisivikelo (is_a noma kuyinto) Ubuhlobo esiba yokwehlayo taxonomic ( subtyping ).

Isinqumo sokuthi ubudlelwane obunengqondo kakhulu bento nokwenziwe ngaphansi kwayo akuhlali kukhanya ngokusobala bunakho-a noma bu-a . Ukudideka ngenxa yezinqumo ezinjalo kudale ukuthi kudalwe la magama wensimbi. Isibonelo esihle se- has- ubuhlobo yizitsha eziku- C ++ STL .

Ukufingqa ubudlelwano, sinabo

  • I-hypernym - ubudlelwane obusezingeni eliphakeme (supertype-subtype) phakathi kwezinhlobo (amakilasi) obuchaza isikhundla se-taxonomic, lapho
    • ubudlelwane befa : i-hypnot (subtype, subclass) inobudlelwano bohlobo ( of- is ) ne-hypernym yayo (supertype, superclass);
  • ubudlelwane - ubudlelwane ( ubudlelwane / bonke / isitsha-ingxenye / ingxenye / ilungu) phakathi kwezinhlobo (amakilasi) okuchaza isikhundla esiphakeme, lapho
    • okuhlanganisiwe (ie ngaphandle kobunikazi) ubudlelwane:
      • a holonym (lonke) has a has-ubuhlobo nge meronym yayo (ingxenye),
    • Ukwakheka (ie. ngobunikazi) ubudlelwane:
      • a meronym (abamelwe) has a ingxenye-of ubudlelwano ne holonym yayo (inhlangano),
    • kokuqukethwe [1] okuhlobene:
      • a meronym (ilungu) has a member of ubudlelwano ne holonym yayo ( isitsha );
  • Ubuhlobo be-mqondo-into (uhlobo-ithokheni) ubudlelwane phakathi kwezinhlobo (amakilasi) nezinto (izimo), lapho
    • nethokheni (into) ine Ngokwesibonelo-of ubuhlobo nge uhlobo lwayo (ekilasini).
Imodeli yobudlelwano bebhizinisi

Kwidatha ene-a-ubudlelwano buvame ukumelwa kumodeli yobudlelwano bezinhlangano. Njengoba ubona ngomdwebo ngakwesokudla i-akhawunti ingaba nezinhlamvu eziningi. Lokhu kukhombisa ukuthi i-akhawunti inobudlelwano "no-has-a" nomlingiswa.

Umdwebo wesigaba se- UML



</br> Ukusetshenziswa okungalungile kokwakhiwa nokuhlanganiswa

Ohlelweni olususelwe entweni lobu budlelwano bungamelelwa ngomdwebo obizwa nge-Unified Modeling Language Class . Lokhu kunobudlelwano futhi kwaziwa njengokuqamba. Njengoba ukwazi ukubona ku-Class Diagram ngakwesokudla imoto "ine-a" carburetor, noma imoto "yakhiwa" yi-carburetor. Lapho idayimane linombala omnyama libonisa ukwakheka, ie into eseceleni eliseduzane nedayimane yenziwe noma iqukethe enye into. Ngenkathi idayimane elimhlophe lisho ukuhlangana, okusho ukuthi into eseduzane nedayimane ingaba nayo noma ibe nenye into.

Enye indlela yokuhlukanisa phakathi kokwakheka nokuhlanganiswa kokumodela umhlaba wangempela, ukucabanga isikhathi sokuphila sento equkethwe. Isibonelo, uma into yemoto iqukethe into ye-Chassis, i-Chassis cishe ngeke ithathelwe indawo ngesikhathi sokuphila kweMoto. Kuzoba nesikhathi sokuphila esifanayo nemoto uqobo; ngakho-ke ubuhlobo bungobunye bokuqamba . Ngakolunye uhlangothi, uma into yeCarl iqukethe iqoqo lezinto zaseTire, lezi zinto zaseTire zingase ziphele futhi zithathelwe indawo kaningana. Noma uma iMoto iba yinto engasebenziseki, amanye amathaya angatholwa futhi anikezwe enye iMoto. Kunoma ikuphi, izinto zaseTire zinokuphila okuhlukile kunento yemoto; ngakho-ke ubudlelwano bungobunye bokuhlanganiswa .

Uma umuntu enza i-C ++ software Class ukusebenzisa ubudlelwane obuchazwe ngenhla, into yeCar ingequkethe into ephelele yeChassis kwilungu ledatha. Le nto kaChassis izofakwa kumakhi weklasi leMoto (noma ichazwe njengohlobo lwedatha yelungu ledatha nezakhiwo zalo ezinikezwe umakhi. ) Futhi njengoba kungaba yilungu ledatha eliqukethe ngokuphelele lesigaba seMoto, into kaChassis ngeke isaba khona uma into yeklasi leCar izosuswa.

Ngakolunye uhlangothi, amalungu wedatha ye-Car class akhomba izinto zeTire cishe angaba yizinkomba ze-C ++. Izinto zeTire zingasatshalaliswa futhi zisuswe ngaphandle, noma zinikezwe amalungu wedatha ento ehlukile yemoto. Izinto zeTire zizoba nokuphila okuzimele okuhlukile ukusuka lapho kususwe into yeCar.

  1. See also Containment (computer programming).