Qhov Sib txawv ntawm Kev Sib Sau thiab Kev Sib Sau

Cov txheej txheem:

Qhov Sib txawv ntawm Kev Sib Sau thiab Kev Sib Sau
Qhov Sib txawv ntawm Kev Sib Sau thiab Kev Sib Sau

Video: Qhov Sib txawv ntawm Kev Sib Sau thiab Kev Sib Sau

Video: Qhov Sib txawv ntawm Kev Sib Sau thiab Kev Sib Sau
Video: Saib Hnub Zoo sib yua Ua Txij Nkawm 2024, Hlis ntuj nqeg
Anonim

Qhov Tseem Ceeb Qhov Sib Txawv - Aggregation vs Composition

Object-Oriented Programming (OOP) yog ib qho piv txwv zoo hauv kev txhim kho software. Cov khoom yog ib qho piv txwv ntawm chav kawm. Nws tsis tuaj yeem tsim cov khoom ib zaug. Yuav tsum muaj daim ntawv qhia lossis piav qhia los tsim ib qho khoom. Daim ntawv qhia no hu ua chav kawm. Ib chav kawm muaj cov khoom thiab cov txheej txheem. Cov khoom raug tsim los ntawm cov chav kawm. Cov chav kawm thiab cov khoom zoo ib yam li lub hom phiaj thiab lub tsev nyob hauv lub ntiaj teb tiag. Tsim ib lub tsev tsis muaj kev npaj tsim nyog. Ib yam li ntawd, ib chav kawm yog siv los tsim ib yam khoom. Ib yam khoom sib koom tes nrog lwm yam khoom. Ib qhov txuas nrog sawv cev rau kev sib raug zoo ntawm ob lossis ntau yam khoom yog hu ua "kev koom ua ke". Aggregation thiab muaj pes tsawg leeg yog hom kev koom tes. Lawv piav txog kev sib raug zoo ntawm cov chav kawm. Kab lus no tham txog qhov sib txawv ntawm kev sib sau ua ke thiab muaj pes tsawg leeg. Qhov sib txawv tseem ceeb ntawm kev sib sau ua ke thiab muaj pes tsawg leeg yog tias kev sib sau ua ke yog kev sib koom ua ke ntawm ob yam khoom uas piav qhia txog "muaj" kev sib raug zoo thiab kev sib xyaw yog ib hom kev sib sau tshwj xeeb uas txhais tau tias yog tswv.

Kev sib sau yog dab tsi?

Ib qho kev sib raug zoo ntawm ob yam khoom yog qhia los ntawm kos ib kab hauv Unified Modeling Language (UML). Qhov txuas yog ib qho kev sib koom ua ke. UML pab kom tau txais qhov pom kev sawv cev ntawm qhov system. Nws txawv dua li cov lus programming ib txwm. Lub koom haum kuj txhais tau qhov ntau ntawm cov khoom. Lawv yog ib tug rau-ib, ib-rau-ntau thiab ntau-rau-ntau. Thaum ib yam khoom ntawm chav kawm A yog txuam nrog ib qho khoom ntawm chav kawm B, qhov ntawd yog ib qho kev sib raug zoo. Ib qho piv txwv yog tus sau phau ntawv. Hauv qhov piv txwv ntawd, ib tus kws sau ntawv sau ib phau ntawv.

Thaum ib yam khoom ntawm chav kawm A yog txuam nrog ntau yam khoom ntawm chav kawm B, nws yog ib qho kev sib raug zoo. Ib qho piv txwv yog, ib chav haujlwm tuaj yeem muaj ntau tus neeg ua haujlwm. Thaum cov khoom ntawm chav kawm A yog txuam nrog ntau yam khoom ntawm chav kawm B thiab ib yam khoom ntawm chav kawm B yog txuam nrog ntau yam khoom ntawm chav kawm A, nws yog ntau-rau-ntau lub koom haum. Ib qho piv txwv yog, tus neeg ua haujlwm tuaj yeem ua haujlwm ntawm ntau qhov haujlwm thiab ib qhov project tuaj yeem muaj ntau tus neeg ua haujlwm.

Aggregation yog hom koom haum uas piav qhia ntxiv txog kev sib raug zoo ntawm cov khoom. Aggregation piav qhia "muaj" kev sib raug zoo. Qee qhov piv txwv uas piav txog kev sib raug zoo yog, tus menyuam kawm ntawv "muaj" tus menyuam kawm ntawv ID, lub tsheb "muaj" lub cav. Nws kuj tseem tuaj yeem nthuav dav ntau nrog kev sib raug zoo. Qee qhov piv txwv yog, lub tsev txhab nyiaj "muaj ntau" cov txhab nyiaj hauv txhab nyiaj, ib chav kawm "muaj ntau" cov tub ntxhais kawm. Nws tuaj yeem piav qhia siv qhov piv txwv hauv qab no.

Qhov txawv ntawm Aggregation thiab Composition
Qhov txawv ntawm Aggregation thiab Composition

Daim duab 01: Kev sib sau ua ke

Raws li cov piv txwv saum toj no, chav kawm muaj cov tub ntxhais kawm lossis ntau tus tub ntxhais kawm. Multiplicity kuj tseem siv los qhia cov khoom siv. Nws piav qhia tias ib chav kawm muaj ntau tus tub ntxhais kawm. Lub cim ntawm pob zeb diamond sawv cev rau kev sib sau ua ke hauv UML. Cov khoom siv ntawm cov tub ntxhais kawm tsis yog nyob ntawm cov khoom siv hauv chav kawm. Yog tias cov khoom hauv chav kawm raug rhuav tshem, nws yuav tsis cuam tshuam rau cov tub ntxhais kawm cov khoom. Cov khoom ntawd tseem yuav muaj nyob.

Kev sib sau yog dab tsi?

Cov khoom xyaw yog ib hom kev sib sau ua ke. Nws piav txog kev ua tswv cuab. Nws tuaj yeem piav qhia siv qhov piv txwv hauv qab no.

Qhov tseem ceeb sib txawv ntawm Aggregation thiab Composition
Qhov tseem ceeb sib txawv ntawm Aggregation thiab Composition

Daim duab 02: Kev sib sau

Raws li cov lus saum toj no, phau ntawv khoom muaj cov nplooj ntawv lossis nplooj ntawv. Multiplicity kuj tseem siv los qhia cov khoom siv. Nws piav qhia tias ib chav kawm muaj ntau tus tub ntxhais kawm. Lub cim ntawm pob zeb diamond uas tseem ceeb sawv cev rau qhov muaj pes tsawg leeg hauv UML. Raws li phau ntawv muaj ib nplooj ntawv lossis ntau nplooj ntawv, nws yog ib qho kev sib sau ua ke, tab sis nws tau teev ntau dua. Yog tias phau ntawv khoom raug rhuav tshem, ces cov nplooj ntawv tseem raug rhuav tshem. Cov nplooj ntawv tsis tuaj yeem nyob tsis muaj phau ntawv. Yog li ntawd, qhov muaj pes tsawg leeg yog ib daim ntawv tshwj xeeb ntawm kev sib sau ua ke uas txhais tau tias yog tswv.

Dab tsi yog qhov zoo sib xws ntawm kev sib sau ua ke thiab kev sib xyaw?

  • Ob leeg siv rau hauv Object Oriented Programming.
  • Ob leeg yog siv hauv Kev Ua Qauv Ua Qauv Lus (UML) kom tau txais kev nkag siab ntawm qhov system.

Qhov txawv ntawm Kev Sib Sau thiab Kev Sau Ua Li Cas?

Aggregation vs Composition

Kev sib sau ua ke yog kev sib koom ua ke ntawm ob yam khoom uas piav txog "muaj" kev sib raug zoo. Cov khoom xyaw yog hom tshwj xeeb tshaj plaws ntawm kev sib sau ua ke uas txhais tau tias yog tswv.
UML Cim
Aggregation is denoted by a pob zeb diamond. Kev sib xyaw yog qhia los ntawm pob zeb diamond tseem ceeb.
Hauv kev sib sau, yog tias tus tswv khoom puas tsuaj, nws yuav tsis cuam tshuam rau cov khoom uas muaj. Hauv kev sib xyaw, yog tias tus tswv khoom raug rhuav tshem, nws yuav cuam tshuam rau cov khoom muaj.

Summary – Aggregation vs Composition

Object-Oriented Programming yog lub ntsiab lus tseem ceeb hauv kev txhim kho software. Hauv OOP, lub kaw lus tau ua qauv siv cov khoom. Cov khoom no tsis muaj nyob hauv kev sib cais. Cov khoom sib koom tes nrog lwm yam khoom. Kev sib raug zoo ntawm cov khoom yog hu ua kev koom ua ke. Aggregation thiab muaj pes tsawg leeg yog hom kev koom ua ke. Qhov sib txawv ntawm kev sib sau ua ke thiab muaj pes tsawg leeg yog tias kev sib sau ua ke yog kev sib koom ua ke ntawm ob yam khoom uas piav qhia txog "muaj" kev sib raug zoo thiab kev sib xyaw ua ke yog ntau hom kev sib sau tshwj xeeb uas qhia txog kev ua tswv cuab. Kev sib sau ua ke thiab kev sib xyaw ua ke ob leeg pab kom nkag siab tus cwj pwm ntawm qhov system.

Download the PDF Version of Aggregation vs Composition

Koj tuaj yeem rub tawm PDF version ntawm kab lus no thiab siv nws rau offline lub hom phiaj raws li daim ntawv ceeb toom. Thov download PDF version ntawm no Qhov txawv ntawm Kev Sib Sau thiab Kev Sau

Pom zoo: