INTRODUCTION
Now Adays, we have different sorts of people some are orderly, others are lackadaisical, a handful are hardworking, and a few are reserved.
What am i trying to say?, because we have so many people with different characters, these people will also have their different approaches to evaluating things. Take for example!.
• Orderly People - always plan their things out
• Lackadaisical People - are laid back
• Hardwojung People - always persevere
• Reserved People - are always withdrawn.
Notice the trend, the same way attitudes vary among people, also applies to the logic behind the variety of programming techniques out there.
What is a programming paradigm? - A programming paradigm is a fundamental style of programming that deals with the creation of software, based on some basic principles.
These principles all have their different ways or styles of operation.
They include
● OOP(Object oriented Programming) - a paradigm where everything operates based on objects (related entities) and their classes(group)
● Event Driven Programming - a paradigm where the users interaction with an applications events are all that matters, e.g first event tapped - first to be called.
● Imperative Programming - a programming paradigm based on a commanding style - this follows an exact way a program is written without any modifications.
There are still many more paradigms including
● Functional Programming
● Aspect Oriented Programming e.t.c.
and so on, but today we'd be majoring on OOP.
OOP(Object oriented Programmimg) -
Just like i said earlier like many other paradigms, OOP also has it's style of software creation. It's is one of the most widely used programming paradigms, being supported by many modern programming languages including - Python, Javascript, Java and Golang(Go).
When we say a program was written with the OOP style - it literally means the entirety of the program was broken down into simpler units of relation called classes and objects, and literally everything is an object e.g can be assigned to a variable.
Classes - these are a collection of related fields of a particular entity that help group relations together.
Objects - these are units or rather blueprints of classes, they help break down the different possible types of a class.
E.g A Car class will have many attributes(fields) including Name, Brand, Production Year, Price, Color and so on. And the objects of the car class, will help break down the different possible car types e.g
Car1 - Name(Sports Car), Brand(Lamborghini), Production Year(2012), Price($400,000), Color(Red).
CODE IMPLEMENTATION
Let's say you are a car dealer, and you need to develop an application that displays the different qualities of your car to buyers, when the buyer clicks on the car - it displays the qualities, OOP will be a great fit for this job.
In the Example below we'd be using the Python programming language to implement this task, as its syntax is subtle.
Car Dealership
These are the parts, the car dealership deals with, Car - (Brand, Color, Publication, Price)
So we have 4 cars currently at the dealership.
To implement, we go as follows.
1 Class Cars:
def init(self, brand, color, publication, price):
self.brand = brand
self.color = Color
self.publication = publication
self.price = price
def onclick_show_details(self):
print("The car you clicked is a {}, it is color {}. It was produced in{}, and its price is {}").format(self.brand, self.color, self.publication, self.price)
This instantiates the class to create objects
car1 = Cars("Lamborghini", "red", "2012", 300000)
car2 = Cars("Toyota", "blue", "2008", 250000)
car3 = Cars("Honda", "white", "2017", "150000)
car4 = Cars("Nissan", "green", "2013", "100000)
This performs actions on the objects by invoking object methods
Car1_details = car1.onclick_show_details()
print(Car1_details)
The car you clicked is a Lamborghini, it is color red, it was produced in 2012 and its price is 300000.
CONCLUSION - There are still many more concepts on OOP including characteristics of OOP e.g, Abstraction, Polymorphism, Encapsulation and Inheritance, but we'd talk about that in another article.
OOP is a really used programming paradigm now adays, so it will be great to learn and grasp it's concept.
Top comments (0)