Class vs Object
Class
A class is a blueprint for creating objects. It defines variables and methods that represent the structure and behavior of a specific object.
Object
An object is an instance of a class. When a class is instantiated, it becomes an object in memory. In the analogy of a car, a class is like the blueprint or design of the car, and an object is the actual, tangible car created based on that blueprint. Creating an object from a class is done using the new
keyword.
Procedural vs Object-Oriented Programming
Procedural Programming
- Processes tasks in a step-by-step manner.
- C language is a representative example.
- Similar to the computer's processing structure, leading to fast execution.
- Maintenance can be challenging.
Object-Oriented Programming
- Considers data and procedures as a single unit.
- Encapsulation: Data and algorithms (code) are grouped into a single unit.
- Inheritance: Allows the creation of a new class by inheriting from an already existing class.
- Polymorphism: One name (method) can be used for various situations.
💡 It's not always about using only object-oriented languages; there are pros and cons depending on the situation.
Function vs Method
Function
- A code snippet that performs a specific task.