Website Design United States, Website Design California, Website Designing United States, Website Designing California

What is Encapsulation?

What is Encapsulation (or Information Hiding)?

Information hiding is leaving out some details of implementation? on purpose from the public. Encapsulation is, besides hiding, to provide common interfaces.

The motivation of information hiding is to reduce dependency between client code and internal structure and its manipulation code. Client code can store and retrieve data via interfaces, or if not needed, no mechanism to access hidden code or date is provided. Accessing hidden data and code is usually designed to cause compile-time? or run-time? error. The implementation? or structure can be modified without affecting code using the structure?.

For example, if the state of a point is represented internally with Cartesian coordinates then this might be changed to polar coordinates without changing the interface of the object, i.e, without changing which messages with which arguments are understood by the object and what the type of the result of these messages will be.

Reducing dependency is the primary motivation for modularization, dividing the program into independent, interchangeable modules. Many modularization mechanisms such as namespaces and objects in object-oriented programming provide an access control for defining which code or data can be accessed externally or not.

After details are hidden, a unified interface can be offered instead. Hiding details and providing common interfaces? is called encapsulation, which is an analogy from making an object look like it's covered by a capsule (the interface? in this case). This allows two objects differing in internal representation but having a common interface to be interchangeably usable (called interchangeability). Interfaces also allow to facilitate the use of data structure and guard the state of the object from invalid input or modification of the structure. For instance, a percentage may be represented by an integer that allows numbers larger than 100. The code to update this integer can then ensure that it never rises above 100.

Many languages allow the programmer to bypass encapsulation, or to specify varying degrees of encapsulation for specific object types. In C#, for example, a class might be defined like this:

class Cow extends Mammal { public Tail m_tail; private Horns m_horns; public void eat(Food f) { super.eat(f); chewcud(); } private void chewcud() { . . . } }

With the Cow type as defined above, some piece of code external to Cow's implementation would be allowed to access m_tail directly, without going through any of the methods that Cow has chosen to expose as its interface. Such code would not, however, be able to access m_horns. Likewise, the method eat() is exposed as part of the Cow's interface, so any other object would be able to cause the cow object to eat by calling that method, passing it the offered food item as an argument to the method. External code would not be able to directly cause the cow to call its chewcud() method (nor would it even know such a method existed; only the cow itself knows or cares that eating involves chewing its cud).

Data hiding implies that data is hidden from the user. In other words, the user only can "see" data that is necessary or relevant to the user, everything else remains hidden.


    Enquiry
 






    Contact us
340 W, 26th Street, Suite F, National City, California - 91950 United States
Tel : 818-667-2853
Info@webbgirrl.com

















 

 

 

 

 

 

 

 

 

 

Ajax Technologies | Foodgear Shop| Lowest Unique Bid Auction | Our Team | Terms And Condition | What is encapsulation | MustInherit class with parameters in the constructor | How to extract src from img elements in html code | How to extract url and anchor from html content | Grab the content of a webpage using C | How to extract the host name from an url C| How to send an email using smtp C | How to remove html tags from web content C | How to convert date time to sql valid string | Set row color in datagrif web from | Disclaimer | How to refresh the data in an xml reader object | Aprendiendo ms access 2000 en 24 horas | Microsoft visual C++ net step by step | Possible to disable a row in listview | Designing sql server 2000 databases for net enterprise | Biztalk server 2000 developer guide for net
© 2008-2009 webbgirrl.com