<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Encapsulation vs Abstraction</title>
	<atom:link href="http://pragmaticcraftsman.com/2006/05/encapsulation-vs-abstraction/feed/" rel="self" type="application/rss+xml" />
	<link>http://pragmaticcraftsman.com/2006/05/encapsulation-vs-abstraction/</link>
	<description>Simplicity from complexity : by Stanley Kubasek</description>
	<lastBuildDate>Sun, 12 Jun 2011 08:12:12 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: More on Encapsulation - The Pragmatic Craftsman</title>
		<link>http://pragmaticcraftsman.com/2006/05/encapsulation-vs-abstraction/#comment-81</link>
		<dc:creator>More on Encapsulation - The Pragmatic Craftsman</dc:creator>
		<pubDate>Thu, 22 Jul 2010 02:59:31 +0000</pubDate>
		<guid isPermaLink="false">http://kubasek.com/blog/pragmatic_craftsman/?p=174#comment-81</guid>
		<description>[...] Encapsulation vs Abstraction, a blog post I wrote a few years ago, is the most popular post on this blog. So I decided to revisit the subject. This time, I want to focus more on encapsulation. [...]</description>
		<content:encoded><![CDATA[<p>[...] Encapsulation vs Abstraction, a blog post I wrote a few years ago, is the most popular post on this blog. So I decided to revisit the subject. This time, I want to focus more on encapsulation. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chintan</title>
		<link>http://pragmaticcraftsman.com/2006/05/encapsulation-vs-abstraction/#comment-36</link>
		<dc:creator>Chintan</dc:creator>
		<pubDate>Thu, 05 Nov 2009 07:06:20 +0000</pubDate>
		<guid isPermaLink="false">http://kubasek.com/blog/pragmatic_craftsman/?p=174#comment-36</guid>
		<description>Excellent article...Now, i am damp sure about this concept...
Below is my understanding. Read it thoughly...
Abstraction comes first, Encapsulation satisfies what abstraction promise to do so.
So, what abstraction says?
Abstraction asked to concentrate on &quot;What&quot; system does and neglect on &quot;How&quot; system does. Let
me put in practical example.
I am very found of design/UML diagrams. When i start my new module, i always begin it with
UML diagrams. Lets says, my requirement is to get some records from sql server to a web page
do some stuffs and then save it to XML file.
So, from UML diagram perspective, i will create one rough box (think it as a class), which fetch some data from database and put it in web page and from web pg to
xml file.
Very important now - here, i ask myself (drawing rough box) as &quot;what&quot; is my requirement?, but i did not concentrate on &quot;how&quot; my requirement will be fulfull(e.g. how many if condition, how many loops etc. etc.). This is abstraction.
Now comes encapsulation: Encapsulation asked to concentrate on &quot;how&quot; to do what abstraction
ask to do  i.e. fetching data from database, put it in web page, save it to xml.
Encapsulation also hide irrelevant details (i.e. informatin hiding)
So, here, we will write
all implementation code to do the stuffs. Methods to open database connection, query it,
assign data to each text box in web pg, create xml nodes, save value to nodes, saving xml
file and many methods. However, all methods are not relevant to developer to know. So, i
will hide (information hiding) method which are not relevant and will only expose those method which will do the stuffs. I will expose methods such as OpenConnection(), SaveDataToWebPg(), SaveToXML().</description>
		<content:encoded><![CDATA[<p>Excellent article&#8230;Now, i am damp sure about this concept&#8230;<br />
Below is my understanding. Read it thoughly&#8230;<br />
Abstraction comes first, Encapsulation satisfies what abstraction promise to do so.<br />
So, what abstraction says?<br />
Abstraction asked to concentrate on &#8220;What&#8221; system does and neglect on &#8220;How&#8221; system does. Let<br />
me put in practical example.<br />
I am very found of design/UML diagrams. When i start my new module, i always begin it with<br />
UML diagrams. Lets says, my requirement is to get some records from sql server to a web page<br />
do some stuffs and then save it to XML file.<br />
So, from UML diagram perspective, i will create one rough box (think it as a class), which fetch some data from database and put it in web page and from web pg to<br />
xml file.<br />
Very important now &#8211; here, i ask myself (drawing rough box) as &#8220;what&#8221; is my requirement?, but i did not concentrate on &#8220;how&#8221; my requirement will be fulfull(e.g. how many if condition, how many loops etc. etc.). This is abstraction.<br />
Now comes encapsulation: Encapsulation asked to concentrate on &#8220;how&#8221; to do what abstraction<br />
ask to do  i.e. fetching data from database, put it in web page, save it to xml.<br />
Encapsulation also hide irrelevant details (i.e. informatin hiding)<br />
So, here, we will write<br />
all implementation code to do the stuffs. Methods to open database connection, query it,<br />
assign data to each text box in web pg, create xml nodes, save value to nodes, saving xml<br />
file and many methods. However, all methods are not relevant to developer to know. So, i<br />
will hide (information hiding) method which are not relevant and will only expose those method which will do the stuffs. I will expose methods such as OpenConnection(), SaveDataToWebPg(), SaveToXML().</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hosting</title>
		<link>http://pragmaticcraftsman.com/2006/05/encapsulation-vs-abstraction/#comment-35</link>
		<dc:creator>Hosting</dc:creator>
		<pubDate>Mon, 10 Aug 2009 07:01:19 +0000</pubDate>
		<guid isPermaLink="false">http://kubasek.com/blog/pragmatic_craftsman/?p=174#comment-35</guid>
		<description>What is difference between encapsulation and abstraction and how are they related to each other?</description>
		<content:encoded><![CDATA[<p>What is difference between encapsulation and abstraction and how are they related to each other?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rohit kumar</title>
		<link>http://pragmaticcraftsman.com/2006/05/encapsulation-vs-abstraction/#comment-34</link>
		<dc:creator>Rohit kumar</dc:creator>
		<pubDate>Mon, 25 May 2009 07:29:53 +0000</pubDate>
		<guid isPermaLink="false">http://kubasek.com/blog/pragmatic_craftsman/?p=174#comment-34</guid>
		<description>Hi Syam, this is for you.......!!
Encapsulation and Data Abstraction
Encapsulation facilitates data abstraction, which is the relationship between a class and its datamembers. Encapsulation refers to the fact that the data variables (also called the properties) and themethods (also called the behavior) are encapsulated together inside a template called a class. The data members encapsulated inside a class may be declared public, private, or protected. However, good object-oriented programming practice requires tight encapsulation. That means all data membersof the class should be declared private. That is, the code outside of the class in which the datamembers are declared can access them only through method calls, and not directly. This is calleddata abstraction (or data hiding), because now the data is hidden from the user, and the user canhave access to it only through the methods.Encapsulation (and data abstraction) makes the code more reliable, robust, and reusable. This isso because the data and the operations on it (methods) are encapsulated into one entity (the class),and the data member itself and the access to it are separated from each other (tight encapsulation or data abstraction). For example, in tight encapsulation, where your data members are private, if you change the name of a data variable, the access code will still work as long as you don’t change the name of the parameters of the method that is used to access it.
Consider the code example in Listing 5-1.
Listing 5-1. TestEncapsulateBad.java1. public class TestEncapsulateBad {2. public static void main(String[] args) {3. EncapsulateBad eb = new EncapsulateBad();4. System.out.println(&quot;Do you have a headache? &quot; + eb.headache);5. }6. }7. class EncapsulateBad {8. public boolean headache = true;9. public int doses = 0;10.}The output from this code follows:Do you have a headache? TrueNote that in line 4, the data variable of class EncapsulateBad is accessed directly by the codepiece eb.headache. This is only possible because the variable headache is declared public in the class EncapsulateBad. If you declare this variable private, line 4 will cause a compiler error. Let’s say you keep it public, and then you change the name of the variable headache in the EncapsulateBad class to something else. In this case, line 4 will again generate an error, because you need to change the name of the variable headache in line 4 to the new name as well.However, a better solution is to separate the data variable from the access by declaring itprivate and provide access to it through methods, as shown in Listing 5-2.Listing 5-2. TestEncapsulateGood.java1. public class TestEncapsulateGood {2. public static void main(String[] args) {3. EncapsulateGood eg = new EncapsulateGood();4. eg.setHeadache(false);5. System.out.println(&quot;Do you have a headache? &quot; + eg.getHeadache());6. }7. }8. class EncapsulateGood {9. private boolean headache = true;10. private int doses = 0;11. public void setHeadache(boolean isHeadache){12. this.headache = isHeadache;13. }14. public boolean getHeadache( ){15. return headache;16. }17. }The output from this code follows:Do you have a headache? falseNote that the variable headache is now declared private (line 9), and it can be accessed throughmethods setHeadache(…) and getHeadache(), which are declared public (lines 11 and 14). The worldcan still access your data, but this access process is separated from the details of the data—the data variable name, how the change is made to it, and so forth. This hiding of the data details from the access procedure is called data abstraction. In an application, it means you can make changes to the data variables in your class without breaking the API. Such protection also makes the code more extendible and easier to maintain. So, the benefits of encapsulation are: hard-to-break reliable code, easy maintenance, and extensibility.
About the AuthorPAUL SANGHERA, Ph.D., SCJP, SCBCD, who contributed to developing the SCJPexam for Java 5, has been programming in Java for 10 years and has substantialexperience teaching Java. As a software engineer, Paul has contributed to thedevelopment of world-class technologies such as Netscape Communicatorand Novell’s NDS. He has been director of software development and directorof project management at successful startups such as WebOrder andMP3.com. He has taught Java and other technology courses at severalinstitutes in the San Francisco Bay Area, including San Jose State University,Golden Gate University, California State University, Hayward, and Brooks College. With a master’s degree in computer science from Cornell University and a Ph.D. in physics from Carleton University, he has authored and co-authored more than 100 technical papers published in well-reputed European and American research journals. Paul has also presented talks by invitation at several international scientific conferences. He is the best-selling author of several books on technology and project management. Paul lives in Silicon Valley, California, where he works as an independent information consultant.</description>
		<content:encoded><![CDATA[<p>Hi Syam, this is for you&#8230;&#8230;.!!<br />
Encapsulation and Data Abstraction<br />
Encapsulation facilitates data abstraction, which is the relationship between a class and its datamembers. Encapsulation refers to the fact that the data variables (also called the properties) and themethods (also called the behavior) are encapsulated together inside a template called a class. The data members encapsulated inside a class may be declared public, private, or protected. However, good object-oriented programming practice requires tight encapsulation. That means all data membersof the class should be declared private. That is, the code outside of the class in which the datamembers are declared can access them only through method calls, and not directly. This is calleddata abstraction (or data hiding), because now the data is hidden from the user, and the user canhave access to it only through the methods.Encapsulation (and data abstraction) makes the code more reliable, robust, and reusable. This isso because the data and the operations on it (methods) are encapsulated into one entity (the class),and the data member itself and the access to it are separated from each other (tight encapsulation or data abstraction). For example, in tight encapsulation, where your data members are private, if you change the name of a data variable, the access code will still work as long as you don’t change the name of the parameters of the method that is used to access it.<br />
Consider the code example in Listing 5-1.<br />
Listing 5-1. TestEncapsulateBad.java1. public class TestEncapsulateBad {2. public static void main(String[] args) {3. EncapsulateBad eb = new EncapsulateBad();4. System.out.println(&#8220;Do you have a headache? &#8221; + eb.headache);5. }6. }7. class EncapsulateBad {8. public boolean headache = true;9. public int doses = 0;10.}The output from this code follows:Do you have a headache? TrueNote that in line 4, the data variable of class EncapsulateBad is accessed directly by the codepiece eb.headache. This is only possible because the variable headache is declared public in the class EncapsulateBad. If you declare this variable private, line 4 will cause a compiler error. Let’s say you keep it public, and then you change the name of the variable headache in the EncapsulateBad class to something else. In this case, line 4 will again generate an error, because you need to change the name of the variable headache in line 4 to the new name as well.However, a better solution is to separate the data variable from the access by declaring itprivate and provide access to it through methods, as shown in Listing 5-2.Listing 5-2. TestEncapsulateGood.java1. public class TestEncapsulateGood {2. public static void main(String[] args) {3. EncapsulateGood eg = new EncapsulateGood();4. eg.setHeadache(false);5. System.out.println(&#8220;Do you have a headache? &#8221; + eg.getHeadache());6. }7. }8. class EncapsulateGood {9. private boolean headache = true;10. private int doses = 0;11. public void setHeadache(boolean isHeadache){12. this.headache = isHeadache;13. }14. public boolean getHeadache( ){15. return headache;16. }17. }The output from this code follows:Do you have a headache? falseNote that the variable headache is now declared private (line 9), and it can be accessed throughmethods setHeadache(…) and getHeadache(), which are declared public (lines 11 and 14). The worldcan still access your data, but this access process is separated from the details of the data—the data variable name, how the change is made to it, and so forth. This hiding of the data details from the access procedure is called data abstraction. In an application, it means you can make changes to the data variables in your class without breaking the API. Such protection also makes the code more extendible and easier to maintain. So, the benefits of encapsulation are: hard-to-break reliable code, easy maintenance, and extensibility.<br />
About the AuthorPAUL SANGHERA, Ph.D., SCJP, SCBCD, who contributed to developing the SCJPexam for Java 5, has been programming in Java for 10 years and has substantialexperience teaching Java. As a software engineer, Paul has contributed to thedevelopment of world-class technologies such as Netscape Communicatorand Novell’s NDS. He has been director of software development and directorof project management at successful startups such as WebOrder andMP3.com. He has taught Java and other technology courses at severalinstitutes in the San Francisco Bay Area, including San Jose State University,Golden Gate University, California State University, Hayward, and Brooks College. With a master’s degree in computer science from Cornell University and a Ph.D. in physics from Carleton University, he has authored and co-authored more than 100 technical papers published in well-reputed European and American research journals. Paul has also presented talks by invitation at several international scientific conferences. He is the best-selling author of several books on technology and project management. Paul lives in Silicon Valley, California, where he works as an independent information consultant.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Syam</title>
		<link>http://pragmaticcraftsman.com/2006/05/encapsulation-vs-abstraction/#comment-33</link>
		<dc:creator>Syam</dc:creator>
		<pubDate>Thu, 02 Oct 2008 16:50:05 +0000</pubDate>
		<guid isPermaLink="false">http://kubasek.com/blog/pragmatic_craftsman/?p=174#comment-33</guid>
		<description>Or is abstraction the ability to define an abstract method, class, interface? Sorry for pulling things down to the implementation level, but I need that to understand concretely.</description>
		<content:encoded><![CDATA[<p>Or is abstraction the ability to define an abstract method, class, interface? Sorry for pulling things down to the implementation level, but I need that to understand concretely.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Syam</title>
		<link>http://pragmaticcraftsman.com/2006/05/encapsulation-vs-abstraction/#comment-32</link>
		<dc:creator>Syam</dc:creator>
		<pubDate>Thu, 02 Oct 2008 15:09:52 +0000</pubDate>
		<guid isPermaLink="false">http://kubasek.com/blog/pragmatic_craftsman/?p=174#comment-32</guid>
		<description>What does it mean for a programming language to support abstraction? I thought if you are able to create a class and instantiate objects, then ur language supports abstraction. If you are able to assign private/public/protected modifiers, then ur language supports encapsulation. Now, from the discussion here, it seems like I got quite a few things wrong here.
Cant understand why things have to be so complex? Abstraction and Encapsulation are supposedly the pillars of OOP. If there is so much scope for confusion about the pillars themselves,  how can we simplify complex systems using these?</description>
		<content:encoded><![CDATA[<p>What does it mean for a programming language to support abstraction? I thought if you are able to create a class and instantiate objects, then ur language supports abstraction. If you are able to assign private/public/protected modifiers, then ur language supports encapsulation. Now, from the discussion here, it seems like I got quite a few things wrong here.<br />
Cant understand why things have to be so complex? Abstraction and Encapsulation are supposedly the pillars of OOP. If there is so much scope for confusion about the pillars themselves,  how can we simplify complex systems using these?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gaurav Sharma</title>
		<link>http://pragmaticcraftsman.com/2006/05/encapsulation-vs-abstraction/#comment-31</link>
		<dc:creator>Gaurav Sharma</dc:creator>
		<pubDate>Thu, 14 Dec 2006 13:48:21 +0000</pubDate>
		<guid isPermaLink="false">http://kubasek.com/blog/pragmatic_craftsman/?p=174#comment-31</guid>
		<description>I think Abstraction is hiding unwanted details, like we have a customer object which uses a very complex data access layer to fetch the Customer from DataBase. Its only programmers headache to thin and implement that layer. There is no need for end user to nkow How this Customer is fetched from DB? Which Db is he using? What&#039;s the connection string like?....and all that complex stuff...All he knows is that, he wants to get information about XYZ Customer and he gets it by selecting his name from the Combo box and clicking &#039;Show Details&#039; button.
On the other hand Encapsulation means , grouping together the data and operations that we are going to perform on that data together. This means creating a class with variables, properties and functions. We provide a specific interface using which user can manipulate this data. If we provide a function GetCustomerSalary(string CustomerName)...then to get a Customer&#039;s Salary .. user will allways have to provide Customer name as there is no other way he can do that (else provided by programmer).
Its simple you have a car and you know how to drive it. Just use the keys and turn them to start the car. What happens inside is not the drivers job. This is abstraction.
Once you are inside the car and you want to change the gear, you can only do that using the interface provided i.e. Gear Knob. There no other way you can do that. This is encapsulation.</description>
		<content:encoded><![CDATA[<p>I think Abstraction is hiding unwanted details, like we have a customer object which uses a very complex data access layer to fetch the Customer from DataBase. Its only programmers headache to thin and implement that layer. There is no need for end user to nkow How this Customer is fetched from DB? Which Db is he using? What&#8217;s the connection string like?&#8230;.and all that complex stuff&#8230;All he knows is that, he wants to get information about XYZ Customer and he gets it by selecting his name from the Combo box and clicking &#8216;Show Details&#8217; button.<br />
On the other hand Encapsulation means , grouping together the data and operations that we are going to perform on that data together. This means creating a class with variables, properties and functions. We provide a specific interface using which user can manipulate this data. If we provide a function GetCustomerSalary(string CustomerName)&#8230;then to get a Customer&#8217;s Salary .. user will allways have to provide Customer name as there is no other way he can do that (else provided by programmer).<br />
Its simple you have a car and you know how to drive it. Just use the keys and turn them to start the car. What happens inside is not the drivers job. This is abstraction.<br />
Once you are inside the car and you want to change the gear, you can only do that using the interface provided i.e. Gear Knob. There no other way you can do that. This is encapsulation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stanley</title>
		<link>http://pragmaticcraftsman.com/2006/05/encapsulation-vs-abstraction/#comment-30</link>
		<dc:creator>stanley</dc:creator>
		<pubDate>Wed, 06 Sep 2006 11:10:25 +0000</pubDate>
		<guid isPermaLink="false">http://kubasek.com/blog/pragmatic_craftsman/?p=174#comment-30</guid>
		<description>Chauhan,
Not sure what you mean. The way you explain it makes it even more confusing...
You want to think about your system on a higher level, using class names, using real objects. That&#039;s abstraction -- not having to concentrate on low-level details. For instance, when constructing a house, you don&#039;t concentrate on what nails will be used (low level detail, not enough abstraction), you concentrate on how many rooms, etc (high level -- nicely abstracted).
Encapsulation, in a way, is the implementation of abstraction. By encapsulating, you hide the internals of the method, or a class. Read the section of this article on encapsulation, &quot;Information hiding allows for implementation of a feature to change without affecting other parts that are depending on it.&quot;</description>
		<content:encoded><![CDATA[<p>Chauhan,<br />
Not sure what you mean. The way you explain it makes it even more confusing&#8230;<br />
You want to think about your system on a higher level, using class names, using real objects. That&#8217;s abstraction &#8212; not having to concentrate on low-level details. For instance, when constructing a house, you don&#8217;t concentrate on what nails will be used (low level detail, not enough abstraction), you concentrate on how many rooms, etc (high level &#8212; nicely abstracted).<br />
Encapsulation, in a way, is the implementation of abstraction. By encapsulating, you hide the internals of the method, or a class. Read the section of this article on encapsulation, &#8220;Information hiding allows for implementation of a feature to change without affecting other parts that are depending on it.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chauhan</title>
		<link>http://pragmaticcraftsman.com/2006/05/encapsulation-vs-abstraction/#comment-29</link>
		<dc:creator>Chauhan</dc:creator>
		<pubDate>Tue, 05 Sep 2006 22:10:36 +0000</pubDate>
		<guid isPermaLink="false">http://kubasek.com/blog/pragmatic_craftsman/?p=174#comment-29</guid>
		<description>&quot;Encapsulation is information hiding. Abstraction means working on a higher level, not worrying about the internal details.&quot; Encapsulation hides data and Abstraction hides implementation then what is the main difference. I think encapsulation is a data binding as information of one object is only related to that one and if that particular object gets destroyed then al information related to that object gets destroyed. Abstraction on the other hand is data hinding technique hides all implementation.</description>
		<content:encoded><![CDATA[<p>&#8220;Encapsulation is information hiding. Abstraction means working on a higher level, not worrying about the internal details.&#8221; Encapsulation hides data and Abstraction hides implementation then what is the main difference. I think encapsulation is a data binding as information of one object is only related to that one and if that particular object gets destroyed then al information related to that object gets destroyed. Abstraction on the other hand is data hinding technique hides all implementation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: manyam</title>
		<link>http://pragmaticcraftsman.com/2006/05/encapsulation-vs-abstraction/#comment-28</link>
		<dc:creator>manyam</dc:creator>
		<pubDate>Sun, 21 May 2006 07:40:06 +0000</pubDate>
		<guid isPermaLink="false">http://kubasek.com/blog/pragmatic_craftsman/?p=174#comment-28</guid>
		<description>Now I am dam clear about the difference... Excellent article.</description>
		<content:encoded><![CDATA[<p>Now I am dam clear about the difference&#8230; Excellent article.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/


Served from: pragmaticcraftsman.com @ 2012-05-19 10:48:57 -->
