History of OOP:
OOP stands for “Object Oriented Programing”. It is a programming language that allows for faster development time and better code organization. OOP originated in the 1960s as a way to simplify programming, but over the years, it is use to grow the programming. Today, it is used in many software programs and applications to create efficient and effective products.
The history of OOP starring with Simula 67, released in 1967. This was a language designed specifically for simulation purposes and was also the first to use classes and objects. Since then, OOP has been incorporated into many languages such as C++ (1983), Java (1995), Python (1991), PHP (1995), C# (.NET Framework, 2002) and JavaScript (1995). Over time more features have been added to make OOP more useful for modern applications.
Introduction of OOP:
Object Oriented Programming (OOP) is a type of programming used to create software. It is based on the concept of Classes and objects, which are self-contained pieces of code that contain both data and functions. OOP also provides better code organization and helps developers maintain and modify existing code more quickly and easily. It is widely used in many different types of applications from web development to game creation.
OOP is a popular and powerful programming strategy. It is used to develop interactive applications, such as computer games, and other more complex software systems. OOP also enables better security by keeping data protected from unauthorized access, which is especially important in enterprise applications. OOP languages such as Java, C++, C#, and Python are widely used in various industries for developing software applications. OOP has many advantages over other programming paradigms, including code reusability, modularity, extensibility, scalability and maintainability.
Why do we need OOP?
In object-oriented programming, it is easy to maintain the code with the help of classes and objects. . OOP also increases code reusability, meaning developers can write code once and use it multiple times across different projects. It provides better control over data structures as well as improved code reuse and extensibility. Additionally, it offers support for polymorphism which allows objects to behave differently depending on their context or state. All these features make object-oriented programming very helpful for writing complex systems with large amounts of data and numerous variables that need to be managed simultaneously.
Basic Object-Oriented Programming (OOP) Concept in C++:
1) Class
Object
Encapsulation
Polymorphism
Inheritance
Abstraction
Class:
In Object Oriented Programming (OOP), a Class is the blueprint and prototype of an object.
Classes are like the blueprints of an object. It contains all the information that an object will need. When you create an object, you are creating an instance of a class. That object will have all the characteristics, or attributes, that you defined in the class.
Object:
In object-oriented programming, an object is an abstract data type with the addition of polymorphism and inheritance. The term "object" can refer to a particular instance of a class, or to the class itself. The term "class" is used to refer to a template for creating objects.
Example:
Animal is the class and dog, cat and cow is the object of the class.
Encapsulation:
Encapsulation in Java is a process of wrapping code and data together into a single unit, for example, a capsule that is mixed with several medicines.
Encapsulation is used to hide the values or state of a structured data object inside a class, preventing unauthorized parties' direct access to them.
We can create a fully encapsulated class in Java by making all the data members of the class private. Now we can use setter and getter methods to set and get the data in it.
Polymorphism:
Polymorphism in Java is a concept by which we can perform a single action in different ways. Polymorphism is derived from 2 Greek words: poly and morphs. The word "poly" means many and "morphs" means forms. So polymorphism means many forms.
There are two types of polymorphism in Java: compile-time polymorphism and runtime polymorphism. We can perform polymorphism in java by method overloading and method overriding.
class Animal {
public void animalSound() {
System.out.println("The animal makes a sound");
}
}
class Pig extends Animal {
public void animalSound() {
System.out.println("The pig says: wee wee");
}
}
class Dog extends Animal {
public void animalSound() {
System.out.println("The dog says: bow wow");
}
}
Inheritance:
Inheritance in Java is a mechanism in which one class acquires all the properties and behaviors of a parent class. It is an important part of OOPs (Object Oriented programming systems).
The idea behind inheritance in Java is that you can create new classes that are built upon existing classes. When you inherit from an existing class, you can reuse methods and fields of the parent class. Moreover, you can add new methods and fields in your current class also.
Abstraction:
Abstraction is a process of hiding the implementation details and showing only functionality to the user.
Another way is it shows only essential things to the user and hides the internal details, for example, sending SMS where you type the text and send the message. You don't know the internal processing of message delivery.
abstract class Bike{
abstract void run();
}
class Honda4 extends Bike{
void run(){System.out.println("running safely");}
public static void main(String args[]){
Bike obj = new Honda4();
obj.run();
}
}