Thursday, 17 January 2008

Object Oriented Programming

 Click Here to View Latest ASP.Net Questions

 OOP Features

Encapsulation � Objects are by nature, encapsulated. That is, only certain portions of their fields and methods are publicly accessible from other classes and one doesn�t really need to know the inner workings of an object in order to use it. Encapsulation has certain benefits. By hiding the inner workings of a class, it makes that class simpler to use because the developer only sees and has access to what is necessary to use the class. Furthermore, the developer cannot accidentally override the data inside that class.

Inheritance � Often considered the "Holy Grail" of programming inheritance is just as often misused or misunderstood. Inheritance defines a particular ability of classes to inherit the data members and functionality from other more generalized classes. The new or "child" class can than add more specific functionality that is parent does not possess.

Polymorphism � Polymorphism is even more difficult to understand and explain. Literally meaning "many forms" polymorphism is the ability for related classes to have the methods or functions with the same name and syntax but different implementations.

Aggregation/Composition � Although these two terms are often used interchangeably, aggregation is more generalized term referring to groups of objects being used to make up another object, much the way a car is made of various parts. Composition is a much more specific form of aggregation where one the pieces can only belong to one whole and outside of that whole, they no longer exist. Usually though, you�ll hear people refer to composition in the more general sense that aggregation defines.

Interfaces � Perhaps one of the most mysterious features of OOP languages, interfaces have very specific purposes, especially in component development. Classes that inherit interfaces are required to have certain methods, fields and/or properties defined and implemented. This allows related classes to have a consistent manner of using them. For example, all the .NET collection classes inherit from the IEnumerator interface, forcing them to have the methods MoveNext(), Reset() and Current property.

No comments:

Post a Comment