{"id":648,"date":"2020-07-21T11:55:39","date_gmt":"2020-07-21T04:55:39","guid":{"rendered":"https:\/\/www.marketenterprise.vn\/blog\/?p=648"},"modified":"2021-12-27T19:46:48","modified_gmt":"2021-12-27T12:46:48","slug":"tinh-ke-thua-inheritance-trong-lap-trinh-huong-doi-tuong","status":"publish","type":"post","link":"https:\/\/www.marketenterprise.vn\/blog\/tinh-ke-thua-inheritance-trong-lap-trinh-huong-doi-tuong.html","title":{"rendered":"T\u00ednh k\u1ebf th\u1eeba (Inheritance) trong l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng"},"content":{"rendered":"<h2 class=\"article-content__title\">4 \u0111\u0103\u0323c ti\u0301nh cu\u0309a l\u00e2\u0323p tri\u0300nh h\u01b0\u01a1\u0301ng \u0111\u00f4\u0301i t\u01b0\u01a1\u0323ng (Object Oriented Programming)<\/h2>\n<ol>\n<li id=\"_tinh-dong-goi-encapsulation-0\"><a href=\"https:\/\/www.marketenterprise.vn\/blog\/tinh-dong-goi-trong-lap-trinh-huong-doi-tuong.html\"><strong>Ti\u0301nh \u0111o\u0301ng go\u0301i (Encapsulation)<\/strong><\/a><\/li>\n<li><a href=\"https:\/\/www.marketenterprise.vn\/blog\/tinh-ke-thua-inheritance-trong-lap-trinh-huong-doi-tuong.html\"><strong>T\u00ednh k\u1ebf th\u1eeba (Inheritance)<\/strong><\/a><\/li>\n<li><a href=\"https:\/\/www.marketenterprise.vn\/blog\/tinh-da-hinh-polymorphism-trong-lap-trinh-huong-doi-tuong.html\"><strong>T\u00ednh \u0111a h\u00ecnh (Polymorphism)<\/strong><\/a><\/li>\n<li><strong>T\u00ednh tr\u1eebu t\u01b0\u1ee3ng (Abstraction)\u00a0<\/strong><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Trong b\u00e0i vi\u1ebft n\u00e0y m\u00ecnh s\u1ebd gi\u1edbi thi\u1ec7u cho c\u00e1c b\u1ea1n bi\u1ebft v\u1ec1 t\u00ednh k\u1ebf th\u1eeba k\u00e8m theo nh\u1eefng v\u00ed d\u1ee5 c\u1ee5 th\u1ec3. \u0110\u1ed1i t\u01b0\u1ee3ng c\u1ee7a b\u00e0i vi\u1ebft n\u00e0y s\u1ebd l\u00e0 c\u00e1c b\u1ea1n ch\u01b0a bi\u1ebft v\u1ec1 l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng, ho\u1eb7c \u0111\u00e3 bi\u1ebft r\u1ed3i nh\u01b0ng mu\u1ed1n hi\u1ec3u r\u00f5 h\u01a1n v\u1ec1 l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng c\u0169ng nh\u01b0 c\u00e1c \u0111\u1eb7c t\u00ednh c\u00f3 li\u00ean quan \u0111\u1ebfn l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng ch\u1eb3ng h\u1ea1n nh\u01b0 t\u00ednh k\u1ebf th\u1eeba \u0111\u01b0\u1ee3c \u0111\u1ec1 c\u1eadp trong b\u00e0i vi\u1ebft n\u00e0y.<\/span><\/p>\n<h2>L\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng (OOP)<\/h2>\n<p><b>L\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng<\/b><span style=\"font-weight: 400;\"> l\u00e0 1 m\u00f4 h\u00ecnh l\u1eadp tr\u00ecnh (programming paradigm) d\u1ef1a tr\u00ean kh\u00e1i ni\u1ec7m c\u1ee7a \u201c\u0111\u1ed1i t\u01b0\u1ee3ng&#8221; (object). \u0110\u1ed1i t\u01b0\u1ee3ng n\u00e0y th\u00f4ng th\u01b0\u1eddng s\u1ebd bao g\u1ed3m c\u00e1c thu\u1ed9c t\u00ednh v\u00e0 c\u00e1c ph\u01b0\u01a1ng th\u1ee9c \u0111\u1ec3 truy xu\u1ea5t ho\u1eb7c thao t\u00e1c tr\u00ean c\u00e1c thu\u1ed9c t\u00ednh c\u1ee7a \u0111\u1ed1i t\u01b0\u1ee3ng \u0111\u00f3.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ch\u1eb3ng h\u1ea1n n\u1ebfu b\u1ea1n \u0111\u1ecbnh ngh\u0129a 1 \u0111\u1ed1i t\u01b0\u1ee3ng l\u00e0 b\u00e1c s\u0129 (Doctor) th\u00ec c\u00e1c thu\u1ed9c t\u00ednh \u0111i k\u00e8m c\u00f3 th\u1ec3 l\u00e0 b\u1eb1ng c\u1ea5p, h\u1ecdc v\u1ecb, chuy\u00ean khoa, th\u00e2m ni\u00ean,.. v\u00e0 c\u00e1c ph\u01b0\u01a1ng th\u1ee9c \u0111i k\u00e8m c\u00f3 th\u1ec3 l\u00e0 t\u01b0 v\u1ea5n, kh\u00e1m b\u1ec7nh,&#8230;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Nh\u01b0ng \u0111\u00f4i l\u00fac b\u1ea1n s\u1ebd ngh\u0129 r\u1eb1ng b\u00e1c s\u0129 chuy\u00ean khoa nhi th\u00ec chuy\u00ean kh\u00e1m b\u1ec7nh cho tr\u1ebb em, b\u00e1c s\u0129 tim m\u1ea1ch th\u00ec chuy\u00ean t\u01b0 v\u1ea5n kh\u00e1m ch\u1eefa b\u1ec7nh cho b\u1ec7nh nh\u00e2n b\u1ecb c\u00e1c b\u1ec7nh l\u00fd v\u1ec1 tim m\u1ea1ch,&#8230; th\u00ec t\u00f4i s\u1ebd di\u1ec5n \u0111\u1ea1t th\u1ebf n\u00e0o? V\u00e2ng, \u0111\u00e2y l\u00e0 1 trong nh\u1eefng l\u00fd do m\u00e0 ch\u00fang ta c\u00f3 t\u00ednh k\u1ebf th\u1eeba trong l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng.<\/span><\/p>\n<h2>T\u00ednh k\u1ebf th\u1eeba (Inheritance)<\/h2>\n<p><b>T\u00ednh k\u1ebf th\u1eeba<\/b><span style=\"font-weight: 400;\"> trong l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng th\u1ec3 hi\u1ec7n m\u1ed1i quan h\u1ec7 cha-con gi\u1eefa c\u00e1c l\u1edbp (classes) v\u1edbi nhau v\u00e0 nh\u1edd v\u00e0o m\u1ed1i quan h\u1ec7 n\u00e0y cho ph\u00e9p l\u1edbp con (child class) th\u1eeba h\u01b0\u1edfng nh\u1eefng \u0111\u1eb7c t\u00ednh c\u1ee7a l\u1edbp cha (parent class), c\u00e1c \u0111\u1eb7c t\u00ednh n\u00e0y c\u00f3 th\u1ec3 bao g\u1ed3m thu\u1ed9c t\u00ednh (attributes) ho\u1eb7c c\u00e1c ph\u01b0\u01a1ng th\u1ee9c (methods) \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a trong l\u1edbp cha.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-655 size-large\" src=\"https:\/\/mevn-public.s3-ap-southeast-1.amazonaws.com\/marketenterprise.vn\/wp-images\/2020\/07\/21113953\/tinh-ke-thua-1-1024x618.png\" alt=\"minh ho\u1ea1 v\u1ec1 t\u00ednh k\u1ebf th\u1eeba\" width=\"960\" height=\"579\" srcset=\"https:\/\/mevn-public.s3-ap-southeast-1.amazonaws.com\/marketenterprise.vn\/wp-images\/2020\/07\/21113953\/tinh-ke-thua-1-1024x618.png 1024w, https:\/\/mevn-public.s3-ap-southeast-1.amazonaws.com\/marketenterprise.vn\/wp-images\/2020\/07\/21113953\/tinh-ke-thua-1-300x181.png 300w, https:\/\/mevn-public.s3-ap-southeast-1.amazonaws.com\/marketenterprise.vn\/wp-images\/2020\/07\/21113953\/tinh-ke-thua-1-768x464.png 768w, https:\/\/mevn-public.s3-ap-southeast-1.amazonaws.com\/marketenterprise.vn\/wp-images\/2020\/07\/21113953\/tinh-ke-thua-1.png 1068w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Trong bi\u1ec3u \u0111\u1ed3 tr\u00ean \u0111\u00e2y\u00a0<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">M\u1ed7i m\u1ed9t h\u00ecnh vu\u00f4ng\/ch\u1eef nh\u1eadt \u0111\u1ea1i di\u1ec7n cho 1 l\u1edbp (class).<br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u201cB\u00e1c s\u0129\u201d ch\u00ednh l\u00e0 l\u1edbp cha (parent class).<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u201cB\u00e1c s\u0129 Chu\u1ea9n \u0110o\u00e1n H\u00ecnh \u1ea2nh\u201d, \u201cB\u00e1c s\u0129 Nhi Khoa\u201d v\u00e0 \u201cB\u00e1c s\u0129 N\u1ed9i Khoa\u201d l\u00e0 c\u00e1c l\u1edbp con (children classes) c\u1ee7a l\u1edbp cha \u201cB\u00e1c s\u0129\u201d v\u00e0 \u0111\u1ec1u k\u1ebf th\u1eeba \u0111\u01b0\u1ee3c c\u00e1c thu\u1ed9c t\u00ednh v\u00e0 ph\u01b0\u01a1ng th\u1ee9c c\u1ee7a l\u1edbp \u201cB\u00e1c s\u0129\u201d .<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">T\u01b0\u01a1ng t\u1ef1 \u201cB\u00e1c s\u0129 Nhi N\u1ed9i Ti\u1ebft\u201d l\u1ea1i l\u00e0 l\u1edbp con c\u1ee7a \u201cB\u00e1c s\u0129 Nhi Khoa\u201d v\u00e0 c\u0169ng k\u1ebf th\u1eeba \u0111\u01b0\u1ee3c c\u00e1c thu\u1ed9c t\u00ednh v\u00e0 ph\u01b0\u01a1ng th\u1ee9c c\u1ee7a l\u1edbp cha t\u01b0\u01a1ng \u1ee9ng.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Vi\u1ec7c l\u1edbp con k\u1ebf th\u1eeba \u0111\u01b0\u1ee3c thu\u1ed9c t\u00ednh hay ph\u01b0\u01a1ng th\u1ee9c n\u00e0o t\u1eeb l\u1edbp cha s\u1ebd \u0111\u01b0\u1ee3c khai b\u00e1o trong l\u1edbp cha th\u00f4ng qua 1 s\u1ed1 t\u1eeb kh\u00f3a nh\u01b0 private, public, protected,&#8230; \u0111\u00e2y l\u00e0 \u0111\u1eb7c t\u00ednh \u0111\u00f3ng g\u00f3i (encapsulation) trong l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng, nh\u01b0ng trong b\u00e0i vi\u1ebft n\u00e0y m\u00ecnh s\u1ebd kh\u00f4ng \u0111\u1ec1 c\u1eadp \u0111\u1eb7c t\u00ednh n\u00e0y.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">N\u1ebfu c\u00e1c b\u1ea1n \u0111\u1ec3 \u00fd th\u00ec l\u1edbp \u201cB\u00e1c s\u0129 Chu\u1ea9n \u0110o\u00e1n H\u00ecnh \u1ea2nh\u201d ngo\u00e0i nh\u1eefng thu\u1ed9c t\u00ednh v\u00e0 ph\u01b0\u01a1ng th\u1ee9c k\u1ebf th\u1eeba t\u1eeb l\u1edbp \u201cB\u00e1c s\u0129\u201d ra th\u00ec c\u00f2n c\u00f3 th\u00eam 1 ph\u01b0\u01a1ng th\u1ee9c \u0111\u1eb7c tr\u01b0ng ri\u00eang c\u1ee7a l\u1edbp n\u00e0y l\u00e0 \u201cSi\u00eau \u00c2m\u201d. \u0110i\u1ec1u n\u00e0y th\u1ec3 hi\u1ec7n r\u00f5 vi\u1ec7c linh \u0111\u1ed9ng v\u00e0 m\u1edf r\u1ed9ng \u0111\u01b0\u1ee3c c\u1ee7a t\u00ednh k\u1ebf th\u1eeba trong l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Ph\u1ea7n b\u00ean d\u01b0\u1edbi s\u1ebd l\u00e0 m\u00e3 ngu\u1ed3n (source codes) \u0111\u1ec3 minh h\u1ecda cho bi\u1ec3u \u0111\u1ed3 b\u00ean tr\u00ean<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-652 size-full\" src=\"https:\/\/mevn-public.s3-ap-southeast-1.amazonaws.com\/marketenterprise.vn\/wp-images\/2020\/07\/21113934\/Screen-Shot-2020-07-21-at-11.22.21-AM.png\" alt=\"\" width=\"598\" height=\"905\" srcset=\"https:\/\/mevn-public.s3-ap-southeast-1.amazonaws.com\/marketenterprise.vn\/wp-images\/2020\/07\/21113934\/Screen-Shot-2020-07-21-at-11.22.21-AM.png 598w, https:\/\/mevn-public.s3-ap-southeast-1.amazonaws.com\/marketenterprise.vn\/wp-images\/2020\/07\/21113934\/Screen-Shot-2020-07-21-at-11.22.21-AM-198x300.png 198w\" sizes=\"auto, (max-width: 598px) 100vw, 598px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-653 size-full\" src=\"https:\/\/mevn-public.s3-ap-southeast-1.amazonaws.com\/marketenterprise.vn\/wp-images\/2020\/07\/21113936\/Screen-Shot-2020-07-21-at-11.22.33-AM.png\" alt=\"\" width=\"596\" height=\"651\" srcset=\"https:\/\/mevn-public.s3-ap-southeast-1.amazonaws.com\/marketenterprise.vn\/wp-images\/2020\/07\/21113936\/Screen-Shot-2020-07-21-at-11.22.33-AM.png 596w, https:\/\/mevn-public.s3-ap-southeast-1.amazonaws.com\/marketenterprise.vn\/wp-images\/2020\/07\/21113936\/Screen-Shot-2020-07-21-at-11.22.33-AM-275x300.png 275w\" sizes=\"auto, (max-width: 596px) 100vw, 596px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">C\u1ea3m \u01a1n b\u1ea1n \u0111\u00e3 xem qua b\u00e0i vi\u1ebft c\u1ee7a m\u00ecnh.<\/span><\/p>\n<h4>Tham kh\u1ea3o<\/h4>\n<ol>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Object-oriented_programming\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Wiki\/Object-oriented<\/span><\/a><\/li>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Inheritance_(object-oriented_programming)#:~:text=In%20object%2Doriented%20programming%2C%20inheritance,inheritance)%2C%20retaining%20similar%20implementation.&amp;text=An%20inherited%20class%20is%20called,parent%20class%20or%20super%20class.\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Wiki\/Inheritance_(object-oriented_programming)<\/span><\/a><\/li>\n<li><a href=\"https:\/\/www.guru99.com\/java-class-inheritance.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">java-class-inheritance<\/span><\/a><\/li>\n<li><span style=\"font-weight: 400;\"><a href=\"https:\/\/vi.wikipedia.org\/wiki\/Khoa_v%C3%A0_chuy%C3%AAn_khoa_(y_h%E1%BB%8Dc)\" target=\"_blank\" rel=\"noopener\">khoa va chuyen khoa y hoc<\/a><\/span><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>T\u00ednh k\u1ebf th\u1eeba l\u00e0 1 trong nh\u1eefng \u0111\u1eb7c tr\u01b0ng ch\u00ednh y\u1ebfu c\u1ee7a l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng. V\u00ec l\u00fd do n\u00e0y n\u00ean tr\u01b0\u1edbc khi m\u00f4 t\u1ea3 chi ti\u1ebft h\u01a1n v\u1ec1 t\u00ednh k\u1ebf th\u1eeba m\u00ecnh mu\u1ed1n chia s\u1ebb v\u1edbi c\u00e1c b\u1ea1n \u0111\u00f4i n\u00e9t v\u1ec1 l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng.\u00a0<\/p>\n","protected":false},"author":18,"featured_media":654,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[34,22],"class_list":["post-648","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-marketenterprise-vietnam","tag-technical"],"_links":{"self":[{"href":"https:\/\/www.marketenterprise.vn\/blog\/wp-json\/wp\/v2\/posts\/648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.marketenterprise.vn\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.marketenterprise.vn\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.marketenterprise.vn\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.marketenterprise.vn\/blog\/wp-json\/wp\/v2\/comments?post=648"}],"version-history":[{"count":0,"href":"https:\/\/www.marketenterprise.vn\/blog\/wp-json\/wp\/v2\/posts\/648\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.marketenterprise.vn\/blog\/wp-json\/wp\/v2\/media\/654"}],"wp:attachment":[{"href":"https:\/\/www.marketenterprise.vn\/blog\/wp-json\/wp\/v2\/media?parent=648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.marketenterprise.vn\/blog\/wp-json\/wp\/v2\/categories?post=648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.marketenterprise.vn\/blog\/wp-json\/wp\/v2\/tags?post=648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}