Abstraction

Write short notes on abstraction .

One of the most fundamental concept of OOPs is Abstraction. Abstraction is a process where you show only “relevant” data and “hide” unnecessary details of an object from the user. For example, when you login to your Amazon account online, you enter your user_id and password and press login, what happens when you press login, how the input data sent to amazon server, how it gets verified is all abstracted away from the you.

Another example of abstraction: A car in itself is a well-defined object, which is composed of several other smaller objects like a gearing system, steering mechanism, engine, which are again have their own subsystems. But for humans car is a one single object, which can be managed by the help of its subsystems, even if their inner details are unknown.

Example

namespace AbstractionDemo
{
    public class Car
    {
        private string _CarName = "Honda City";
        private string _CarColur = "Black";
        public string CarName
        {
            set
            {
                _CarName = value;
            }
            get
            {
                return _CarName;
            }
        }
        public string CarColur
        {
            set
            {
                _CarColur = value;
            }
            get
            {
                return _CarColur;
            }
        }
        public void Steering()
        {
            Console.WriteLine("Streering of the Car");
        }
        public void Brakes()
        {
            Console.WriteLine("Brakes of the Car");
        }
        public void Gear()
        {
            Console.WriteLine("Gear of the Car");
        }
        private void CarEngine()
        {
            Console.WriteLine("Engine of the Car");
        }
        private void DiesalEngine()
        {
            Console.WriteLine("DiesalEngine of the Car");
        }
            private void Silencer()
        {
            Console.WriteLine("Silencer of the Car");
        }
    }
}

Leave Comment

Important Topics

Title
Object Oriented Programming (OOP)
OOP vs POP
Class with Example
Objects
Access Modifiers
Encapsulation with example
C# Properties (GET, SET)
Method and Function
Abstraction
Polymorphism
Operator Overloading
Inheritance
Constructor and its Types
Exception Handling
Throwing an Exception