{"id":807,"date":"2018-11-14T16:20:24","date_gmt":"2018-11-14T16:20:24","guid":{"rendered":"https:\/\/barkhane.com\/php\/2018\/11\/14\/difference-between-abstraction-and-encapsulation-in-php\/"},"modified":"2024-03-03T17:43:13","modified_gmt":"2024-03-03T17:43:13","slug":"difference-between-abstraction-and-encapsulation-in-php","status":"publish","type":"post","link":"https:\/\/barkhane.com\/php\/difference-between-abstraction-and-encapsulation-in-php\/","title":{"rendered":"Difference between Abstraction and Encapsulation in PHP"},"content":{"rendered":"<h2>Abstraction and Encapsulation in PHP<\/h2>\n<p>Difference between Abstraction and Encapsulation<\/p>\n<p><a href=\"https:\/\/barkhane.com\/php\/data-abstraction-in-php\/\"><strong>Abstraction<\/strong><\/a><\/p>\n<p>1. Abstraction solves the problem in the design level.<br \/>\n2. Abstraction is used for hiding the unwanted data and giving relevant data.<br \/>\n3. Abstraction lets you focus on what the object does instead of how it does it<br \/>\n4. Abstraction- Outer layout, used in terms of design.<br \/>\nFor Example:-<br \/>\nOuter Look of a Mobile Phone, like it has a display screen and keypad buttons to dial a number.<\/p>\n<p><a href=\"https:\/\/barkhane.com\/php\/encapsulation-in-php\/\"><strong>Encapsulation<\/strong><\/a><\/p>\n<p>1. Encapsulation solves the problem in the implementation level.<br \/>\n2. Encapsulation means hiding the code and data into a single unit to protect the data from outside world.<br \/>\n3. Encapsulation means hiding the internal details or mechanics of how an object does something.<br \/>\n4. Encapsulation- Inner layout, used in terms of implementation.<br \/>\nFor Example:- Inner Implementation detail of a Mobile Phone, how keypad button and Display Screen are connect with each other using circuits.<\/p>\n<p>The easier way to understand Data Abstraction and data encapsulation is as follows:-<\/p>\n<p><strong>to understand Abstraction and Encapsulation Take an example of Mobile Phone:-<\/strong><\/p>\n<p>You have a Mobile Phone, you can dial a number using keypad buttons. Even you don\u2019t know how these are working internally. This is called Abstraction. You have the only information that is needed to dial a number. But not its internal working of mobile.<br \/>\nBut how the Mobile Phone internally working?, how keypad buttons are connected with internal circuit? is called Encapsulation.<\/p>\n<p>Abstraction and Encapsulation in PHP In summary, while abstraction focuses on defining the essential characteristics and behaviors of objects, encapsulation focuses on bundling data and methods together and controlling access to them. Both concepts are fundamental to creating well-structured, modular, and maintainable <a href=\"https:\/\/barkhane.com\/php\/\">PHP<\/a> code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Abstraction and Encapsulation in PHP Difference between Abstraction and Encapsulation Abstraction 1. Abstraction solves the problem in the design level. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[3],"tags":[],"class_list":["post-807","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/posts\/807","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/comments?post=807"}],"version-history":[{"count":0,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/posts\/807\/revisions"}],"wp:attachment":[{"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/media?parent=807"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/categories?post=807"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/tags?post=807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}