Categories
Programming & Dev

Understanding OOPs Concept: First step towards Software Dev

Principles of OOPs

Everything in this world is an Object-Oriented programming concept, wherever you see, everything has some properties, structure, behaviour, function and features. But how it is related to real-world, can be understood by the top 4 principles of OOPs, which is given below:

  1. Abstraction
  2. Encapsulation
  3. Inheritance
  4. Polymorphism

Abstraction:

Hiding internal features and showing only what is required For example, in a car a driver should only know about how to drive it using gears,steering and pedals but he/she shouldnt bother bout how it is happening internally.

Encapsulation

capsuling or wrapping up everything inside a single body is called encapsulation.
For example, In the same car all the boot spaces, seats, doors and place to sit is there inside a single body , like in a television also switches , screen and ports all are together in a single object not somewhere else, this is a perfect example of encapsulation.

Inheritance

Inheriting previous members from the previously build class into the new class in which we want to add some extra other features is called inheritance.
For example, A car making company will surely add the same things such as steering, 4 wheels , doors , driver equipments but adding some features like long boot space , sunroof , music system,etc. to make it a new body but not a different concept from which it is derived. reusing concept!!!
So we can say , adding extra features has made some special effects so it is termed as specialization

Polymorphism

It means generalization of all the elements under one name that is, all the companies like Toyota, Suzuki, and honda can be generalized under one name that is Car companies.

Understanding classes and object:

Before creating anything, we first engineer its design and then we create several types of product from it having different features, Like in television, first a semiconductor design is built in order to make it properly functional and after that products or objects are produced with several other features. So here, design or concept is the CLASS and products are its objects.


In the world, everything is made up of two things: property and behavior Everything has properties, forex, a television has channels, volume, screen size, screen type, etc, all are its properties. (also class members or design elements) and functions like changing channels, volume, menu, etc are its behaviors.
In a class or design, properties are the member variables and behaviors are the functions of it,
for example:

OOPs
OOPs

Output corresponding to the above code:

OOPs

Data hiding

Now, in this part of OOPs, the main aim is to hide the unnecessary data from user which he/she doesn’t require to read or to get acknowledged. Such as in a car, we may not need to tell them about the function of engine or properties of the engine such as power, BHP, torque and other more details to the user, we will just provide them with the gearbox, steering and pedals to operate it, nothing more. In the same way in a class, we hide all properties or member variables and just put public to functions which are useful for the users. This can be understood with the given code:

Understanding OOPs Concept: First step towards Software Dev 1

Understanding OOPs Concept: First step towards Software Dev 2

Focus on the comments in the given code , those are written to give you more brief idea about the process going in between the codes.

Output corresponding to the above code:

Understanding OOPs Concept: First step towards Software Dev 3

In the above code, we have implemented 3 things , 1st one is the output of the default constructor , 2nd one is the parameterized constructor by coder input and the last one is the user-input constructor implementation.

We can also implement the array of objects with the use of certain commands such as:

subjects sub[]=new subjects[3];
sub[0]=new subjects("DS",100);
sub[1]=new subjects("software engg",100);
sub[2]=new subjects("operating system",100);
 for(int i=0;i<sub.length;i++){
        sub[i].getinfo();
    }

So, this much only for the 1st step , we hope you understood the concept and if not then you can ask doubts in the below comments and also subscribe to the news letter to stay tuned for the second step in this domain

Get the latest tech news and updatesethical hacking tutorials and cybersecurity tips and tricks. Check out MeuSec for more.

Sometimes we include links to online retail stores and/or online campaigns. If you click on one and make a purchase we may receive a small commission.

Comments:

Leave a Reply

Your email address will not be published. Required fields are marked *