Abstraction in Object Oriented Programming (OOPS) Concept

However, you cannot hide an entire object. To use an object, a part of it needs to be accessed by users. To provide this access, abstraction is used. Abstraction provides access to a specific part of data while encapsulation hides the data. Therefore, abstraction and encapsulation compliment each other.
In Object Oriented Programming (OOPS) Concept, abstraction defines the conceptual boundaries of an object. These boundaries distinguish an object from another objects.


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.
Example: When a user designs an application by using existing templates, the complexity of the template is hidden from the user, but the essential features for creating the application are provided to the user. Abstraction enables an object to display these essential features to develop an application.

Encapsulation is a way of organizing data and methods into a structure by concealing the way the object is implemented, i.e. preventing access to data by any means other than those specified. Encapsulation therefore guarantees the integrity of the data contained in the object.


public partial class OOPS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    class House
    {
        // Data Members
        public string BedRoom;
        private string StoreRoom;

        // Member Functions
        private bool EnterBedRoom()
        {
            BedRoom = "The Bed Room";
            return true;
        }

        public bool EnterStoreRoom()
        {
            StoreRoom = "The Store Room"; /* Even though StoreRoom is declared Private, EnterStoreRoom function
        can modify it because the member function itself has access to all other members. */
            return true;
        }

    }

    class MainClass
    {
        public static void Main()
        {
            House ThewhiteHouse = new House();
            ThewhiteHouse.BedRoom = "Main Bed Room"; /* OK - Public Data Member is accessible
        from outside the class */
            ThewhiteHouse.StoreRoom = "Main Store Room"; /* Error - Private Data Member is not accessible
         from outside the class. */
            ThewhiteHouse.EnterBedRoom(); /* Error - Private Member Function is not accessible
        // from outside the class. */
            ThewhiteHouse.EnterStoreRoom(); /* OK - Public Data Member is accessible from outside
        the class. */
        }
    }

}



Screen Shot:
You can check the Accessible Methods and Data Members as follows


EnterBedRoom() method And BedRoom is Private and EnterStoreRoom() Method And StoreRoom is Public Accesibility as Follows…

0 Responses to “Abstraction in Object Oriented Programming (OOPS) Concept”

Post a Comment

Labels

Topics