Object Oriented Programming | what should you know?
While developing and maintaining software applications, having knowledge of Object Oriented Programming (OOP) can be valuable.
Here, we are going to explain basic principles of OOP in an easy to understand way.
What is Object Oriented Programming?
OOP is computer programming model that organizes:
- Software design around data / objects instead of logic and function.
- Well-suited approach for large, complex and actively maintained programs.
- Allows developers to focus on objects rather than logic required for data manipulation.
- In simple terms, an object can be thought as a data field that has unique behavior and attributes.
Object oriented approach allows developers collaborative development: dividing projects into groups.
Object Oriented Programming Benefits for programmers:
These include scalability, reusability and efficiency.
What is scalability? Basically it is an attribute of algorithm and its implementation design.
OOP is a programming paradigm and scalability/ maintainability / testability are independent of it.
Data Modeling: It is the very first step in OOP, involves the collection of all the objects that a programmer wants to manipulate. Then identify how these objects are related to each other.
Once an object is identified, it is labeled with a class. A class is a collection of objects that defines the type of data and any logic sequence that can manipulate objects.
Now, each unique logic sequence is called a method.
Objects can communicate with each other via well-defined messages called interfaces.
4 basic principles of Object Oriented Programming:
In Object oriented programming paradigm, encapsulation is achieved by keeping state of each object private inside a class.
To make changes, other objects do not have access to this class. We can say that encapsulation helps in achieving data hiding.
Ultimately, it provides greater data security feature and prevents data from being corrupted.
Suppose a scenario. We have a game in which there is a cat and there are people. They communicate with each other.
Now, to apply encapsulation, we encapsulate all cat logic into a class named “Cat”.
Here, the state of the Cat is some private variables named mood, hungry and energy.
It also has a private method called meow (). It can call it when it wants. Other classes can’t tell the Cat when to meow ().
Now, what people can do with Cat is defined via public methods Feed (), Play () and Sleep (). Each of them may modify internal state of Cat class and may invoke meow () method.
Hence, the binding between the private state and public methods is made.
This is called encapsulation.
It means hiding un-necessary implementation code. Objects show only those internal operational mechanisms that are relevant for the use of other objects.
Abstraction can be thought as an extension of encapsulation. In OOP, programs are extremely large and objects communicate with each other a lot.
So, maintaining a larger database, with changes along the way, over the years, can be difficult.
Abstraction is a concept to ease this problem.
Think once how you use your mobile phone?
Another common problem in OOP design is objects are very similar and they share common logic. But they are not entirely the same.
So, how can we reuse the common logic and extract the unique logic into a separate class?
One way to achieve this is inheritance…
In simple terms, inheritance means we form a hierarchy. We have a main class called “Parent class” and we create class from it called “Child class”.
Now, child class is richer as compared to its parent class because it reuses all the fields and methods of its parent class + it has its own unique fields or methods.
This feature of OOP allows developers ensuring higher level of accuracy. It reduces development time too.
It means an object can take one or more than one forms depending on the situation.
Which form an object will take upon execution? It is determined by program logic.
In real life, a person behaves like student while in class room. The same person behaves like customer while in market, behaves like son while at home.
This is polymorphism – one object, many forms – one person, multiple behaviors, depending on the context.
List of Object Oriented Programming Languages
Most popular OOP languages are:
- Visual Basic.Net
Criticism on Object Oriented Programming
Main criticism is: Object oriented programming does not focus on algorithms and computations. It over-emphasizes the data component about software development.
It may take long time to write and compile OOP code.
Functional Programming and Structured Programming are some alternative ways to Object Oriented Programming.
Frequently Asked Questions (FAQs)
- What is difference between OOP and Structural Programming?
In structural programming, programs are divided into functions. It provides logical structure. Its top-down approach and does not provide code reusability.
Whereas, OOP is a programming paradigm, that is based on objects instead of just functions and procedures. Its bottom-up approach and provide code reusability.
- Why OOP?
Code maintenance is easy due to encapsulation. This programming
Paradigm is mainly used for relatively big software.
- What is the purpose of Inheritance?
The purpose of inheritance is Code Reusability.
- What are the limitations of inheritance?
To execute a program, programmer requires more time and efforts due to jumping back and forth between many different classes. Inheritance demands careful implementation otherwise it may lead to incorrect results.
- What is the difference between private, public and protected access specifiers?
Let’s have a look at some other MAJOR Programming Paradigms in detail:
Subscribe to FinsliQ Blog:
If you have enjoyed and find our blogs informative, then please support the platform by subscribing to our daily newsletters. Benefits of becoming a subscriber:
- Get daily updates with the latest blogs/article
- New updates within the same subject area are release every day (release dates can be found next to the link in the blog)
- Stay up to date with the latest Tech news
- Variety of different types of blogs
Visit FinsliQ | Tech Academy. A variety of course are available in cloud computing, Dev-ops, Cloud Architecture, Cyber Security and much more.