|Wordane : Classes vs Objects|
Technology has evolved, and so has the way we make technological stuff. Programmers today often fall in the caveat of finding the multiple locations of the piece of code which needs to be updated. To avoid this we must follow a tenet DRY programming
DRY = Don't Repeat Yourself
Object-oriented programming is a style of coding that allows developers to group similar tasks into classes, thus making code easy to maintain and follow DRY. OOP might seem furious and intimidating at the start but is far more simpler than procedural or inline code.
Understanding Objects and Classes
The building blocks of OOP are Classes and Objects, but are not interchangeable terms. In our example lets take an example of a car and how we approach to build it.
|Fig 1. Car Class|
It is the blueprint for a concept. In the fig 1. above there is a blue print at the top, which is the class. It defines the basic layout of a Car (how it would look), even when there is no actual car. A car class defines a moving object on 4 typres (without size of tyres), steering, brake, acceleration.
It is the actual Car built according to the blueprint. In fig 1. we can see car objects to be the derivatives of Car Class in a way that it looks exactly the same, and may have additional individual properties of color, seats and tyre size. Thus all the car manufacturing companies, will follow the same Car Class blueprint, to make a car, however will add additional unique features, which make them unique from one another.
So we will have,
|Fig 2. Car Class and Object definition|
Hence we have a Basic Car Class, and each manufacturer has used the blueprint to create a unique car of its own. Multiple manufacturers can follow the blueprint of car class and create there own car. Each manufacturer can talk to other vendor.
What are Classes and Objects ?
Classes = Structure of data and actions.
Objects = Use the data and action in Classes to build themselves.
- Object cannot exist without a Class.
- Multiple Objects can be created from one Class.
- Objects are independent of each other. But can talk to each other.