Sunday, April 27, 2008

OOPS Concepts

OOPS Concepts are described below: -
  • Class - A class describes all the attributes of objects, as well as the methods that implement the behavior of member objects. It’s a comprehensive data type which represents a blue print of objects. It’s a template of object.
  • Object - An object is the basic building block of object-oriented programming
  • Instance - One can have an instance of a class or a particular object. The instance is the actual object created at runtime. The set of values of the attributes of a particular object is called its state. The object consists of state and the behaviour that's defined in the object's class.
  • Method - In a simple language it is An object's abilities.
  • Message Passing - The process by which an object sends data to another object or asks the other object to invoke a method. Also known to some programming languages as interfacing.
  • Inheritance - It means reusability. Example we have VEHICLE class and we can inherit this class to make more specialized class like CAR, which will add new attributes and use some existing qualities of the parent class. It shows more of a parent-child relationship. This kind of hierarchy is called inheritance.
  • Encapsulation - Encapsulation conceals the functional details of a class from objects that send messages to it in other words It is a process of hiding all the internal details of an object from the outside world. It means that all of the object's data is contained and hidden in the object and access to it restricted to members of that class. Programming languages aren't quite so strict and allow differing levels of access to the object's data. The first three levels of access shown below are in both C++ and C#, with the last two in C#.
    1 . Public : All Objects can access it.
    2 . Protected : Access is limited to members of the same class or descendants.
    3 . Private : Access is limited to members of the same class.
    4 . Internal : Access is limited to the current assembly.
    5 . Protected Internal : Access is limited to the current assembly or types derived from the containing class.
  • Abstraction - It allows complex real world to be represented in simplified manner. Example color is abstracted to RGB. By just making the combination of these three colors we can achieve any color in world.It’s a model of real world or concept.
  • Polymorphism - Polymorphism allows you to treat derived class members just like their parent class' members.
    When inheritance is used to extend a generalized class to a more specialized class, it includes behavior of the top class(Generalized class). The inheriting class often implement a behavior that can be somewhat different than the generalized class, but the name of the behavior can be same. It is important that a given instance of an object use the correct behavior, and the property of polymorphism allows this to happen automatically.

No comments: