Object-oriented programming: Difference between revisions

Content deleted Content added
Encapsulation need to be separated as it is main pillar of OOP.
Line 188:
If a class does not allow calling code to access internal object data and permits access through methods only, this is a strong form of abstraction or information hiding known as [[abstraction (object-oriented programming)|abstraction]]. Some languages (Java, for example) let classes enforce access restrictions explicitly, for example denoting internal data with the <code>private</code> keyword and designating methods intended for use by code outside the class with the <code>public</code> keyword. Methods may also be designed public, private, or intermediate levels such as <code>protected</code> (which allows access from the same class and its subclasses, but not objects of a different class). In other languages (like Python) this is enforced only by convention (for example, <code>private</code> methods may have names that start with an [[underscore]]).
 
'''===Encapsulation''' ===
 
Encapsulation prevents external code from being concerned with the internal workings of an object. This facilitates [[code refactoring]], for example allowing the author of the class to change how objects of that class represent their data internally without changing any external code (as long as "public" method calls work the same way). It also encourages programmers to put all the code that is concerned with a certain set of data in the same class, which organizes it for easy comprehension by other programmers. Encapsulation is a technique that encourages [[Coupling (computer programming)|decoupling]].
 
Encapsulation prevents external code from being concerned with the internal workings of an object. This facilitates [[code refactoring]], for example allowing the author of the class to change how objects of that class represent their data internally without changing any external code (as long as "public" method calls work the same way). It also encourages programmers to put all the code that is concerned with a certain set of data in the same class, which organizes it for easy comprehension by other programmers. Encapsulation is a technique that encourages [[Coupling (computer programming)|decoupling]].
 
===Composition, inheritance, and delegation===