Subtyping hauv OOP yog dab tsi?
Subtyping hauv OOP yog dab tsi?

Video: Subtyping hauv OOP yog dab tsi?

Video: Subtyping hauv OOP yog dab tsi?
Video: TOP 10 Yam Mob Virus Ua Txaus Ntshai Tshaj Plaws 2020 | Ua Rau Neeg Tuag Coob Kawg Nkaus 2024, Kaum ib hlis
Anonim

Subtyping yog ib feem tseem ceeb ntawm OOP - koj muaj ib yam khoom ntawm ib hom tab sis uas ua kom tiav qhov interface ntawm lwm hom, yog li nws tuaj yeem siv nyob qhov twg lwm yam khoom siv tau.

Hais txog qhov no, dab tsi yog subtyping hauv C ++?

C++ muab qhov mechanism thiab hu subclasses "derived classes". subtyping hais txog qhov muaj peev xwm siv qhov tseem ceeb ntawm cov subtype nyob rau hauv qhov chaw uas yuav tsum muaj nuj nqis ntawm hom.

Tsis tas li ntawd, qhov txawv ntawm subclass thiab subtype yog dab tsi? A subclass ib txwm nws tus kheej yog chav kawm. Subtype yog ib lo lus dav dav dua, thiab peb tuaj yeem hais tias ib hom yog a subtype ntawm lwm hom, yam tsis tau hais dab tsi txog lawv yog dab tsi (chav kawm, interface thiab lwm yam).

Hais txog qhov no, dab tsi yog subtyping hauv Java?

Subtyping tsuas yog txhais tau hais tias kev ua haujlwm ntawm supertype tuaj yeem ua tiav ntawm subtype . hauv Java , interfaces sawv cev rau cov qauv piav qhia txog tus cwj pwm dab tsi uas ib hom tuaj yeem nthuav tawm, uas ua rau nws lub cev sawv cev rau subtyping . Subclassing yog manifested nyob rau hauv lub chav kawm hierarchy.

Puas yog tag nrho cov subtypes subclasses?

Muaj qhov sib txawv tseem ceeb ntawm subtypes thiab subclass hauv kev txhawb nqa rov siv dua. Subclasses tso cai rau ib tug rov siv cov cai hauv cov chav kawm - ob qho tib si cov lus tshaj tawm sib txawv thiab cov lus txhais. Ceeb toom tias cov subtype Kev sib raug zoo tsuas yog nyob ntawm pej xeem cuam tshuam ntawm cov khoom, tsis yog lawv cov kev siv.

Pom zoo: