Advantages of using
Objects and Object Oriented programming as compared to method based
programs are:-
- OOP(Object Oriented Programming) is very close to the
real world that uses classes and objects to group similar
data for a better understanding and modification of the code. It is
easier to conceptualize as compared to method based
programs.
- In OOP(Object Oriented Programming) we can use
Inheritance which increases code reusability and decreases
the code length. A child class can inherit the properties
and behaviours(objects and functions) from its parent class,
therefore we don't need to write the same functions each and every
time from the scratch. This is not possible in method based
programming.
- We can use the concept of Encapsulation in OOP, which
helps in data hiding and keeping it private by restricting its
access. This is also not possible if there is no
implementation of objects.
- OOP also provides us with Polymorphism by overloading
or overriding the functions. It helps the programmers to
reuse the code and saves a lot of time. Once the code is written
and tested, we can use it several times by just changing its
parameters. Therefore, it's not needed to write and test the
functions each and every time from the scratch.
- OOP introduces shallow, deep and object copy
which is missing in method based programs. Therefore
functionalities can be copied according to the situations.
- Introduces the concept of observer pattern so that if a
particular object within a class got modified then extended data
member which is dependent on that object gets updated
without any further modification of the code.
Disadvantages of using
only methods in our programs are:-
- We won't be able to inherit functionalities and therefore code
length will increase.
- We won't be able to protect our private data as access can't be
restricted if we use only methods in our programs.
- Code complexity can increase and it may become difficult to
debug and manage if there are no links between the similar
functions and is not defined into manageable chunks.