Monday 19 December 2011

OOP Design Principles


Introduction: we will discuss the OOPs concepts along with  fundamentals  used to develop the .Net applications and programs. An application that implements Object-Oriented Programming (OOP) concepts is distinguished by four design principles. The four design principles are encapsulation, abstraction, inheritance, and polymorphism.

OOP means Object Oriented Programming. This is a technique used to create programs around the real world entities. In OOPs programming model, programs are developed around objects and data rather than actions and logics. In OOPs, every real life object has properties and behavior. This feature is achieved in java through the class and object creation. They contains properties (variables of some type) and behavior (methods). OOPs provides better flexibility and compatibility for developing large applications.
Class: A class defines the properties and behavior (variables and methods) that is shared by all its objects. It is a blue print for the creation of objects.
Object:  Object is the basic entity of object oriented programming language. Class itself does nothing but the real functionality is achieved through their objects. Object is an instance of the class. It takes the properties (variables) and uses the behavior (methods) defined in the class. 
ENCAPSULATION
Encapsulation hides the inner workings of an object from outside users of the object. This protects outside users from making internal changes or optimizations to such objects. The object needs only to maintain its external functionality to support its clients. Internal details, such as data representation, should not be accessible externally.
ABSTRACTION
The principle of abstraction is modeling real-world objects as objects in Java. However, these objects are only modeled at a certain level of detail. Only the behavior and data that is needed by your application will be included in your model.
The abstraction design principle focuses on the essential characteristics of an object. In OOP, abstraction defines the conceptual boundaries of an object. These boundaries distinguish one type of object from another
INHERITANCE
The inheritance design principle allows a class to inherit the characteristics of another class. When inheritance is used in an application, the application consists of classes that are arranged in hierarchies. The classes defined at the lower levels of a hierarchy inherit from the classes higher up in the hierarchy.
By creating a hierarchy of classes, the characteristics and code of a class are made reusable. A class can inherit characteristics from other classes and provide additional features. The new class has its own attributes and the attributes of the existing class. This feature provides extensibility and reusability in classes.
POLYMORPHISM
Polymorphism refers to the ability of an object to take on different forms depending upon the situation. Consider an example of a class Sedan that inherits from the class Car that inherits from the class Vehicle. An instance of the Sedan class can be referred to as a Sedan, a Car, or a Vehicle.
Polymorphism provides flexibility to an application based on requirements. It simplifies coding and reduces the rework involved in developing and modifying an application. This is because different types of objects can react to the same type of stimulus.

No comments: