Object Oriented Programming
Object Oriented Programming
instantiation of an object
greeting person1
printing name & age
Advantages of OOP
• It provides a clear modular structure for programs that enhances code
reusability.
• It provides a simple way to solve complex problems.
• It helps define more abstract data types to model real-world
scenarios.
• It hides implementation details, leaving a clearly defined interface.
• It combines data and operations.
Class
• Definition of the structure that we want (similar to function
definition); needs to be instantiated first before you can use it
• Convention: use “CapWords” for class name
Process:
• Change the parent class method in the child class by defining a
method with the same name and same number of parameters
Example: Method Overriding
Inheriting and Updating
Attributes
Definition:
• Create child class with attributes that differ from parent class
Note:
• Some attributes should remain the same
• Child class could have additional / fewer attributes
Process:
• Use super method to refer to attributes to be inherented from parent class
Example: Updating Attributes
error
Example: Encapsulation
In procedural programming, the program is divided into small parts In object-oriented programming, the program is divided into small
called functions. parts called objects.
Procedural programming follows a top-down approach. Object-oriented programming follows a bottom-up approach.
Adding new data and functions is not easy. Adding new data and function is easy.
Procedural programming does not have any proper way of hiding data Object-oriented programming provides data hiding so it is more
so it is less secure. secure.
In procedural programming, there is no concept of data hiding and In object-oriented programming, the concept of data hiding and
inheritance. inheritance is used.
Procedural programming is used for designing medium-sized Object-oriented programming is used for designing large and complex
programs. programs.
Procedural programming uses the concept of procedure abstraction. Object-oriented programming uses the concept of data abstraction.
Code reusability absent in procedural programming, Code reusability present in object-oriented programming.
References
• Robertson L.A., Simple Program Design: A step-by-step approach
• Chapter 11: An introduction to object-oriented design
• Kong Q., Siauw T., Bayen A.M., Python Programming and Numerical
Methods
• Chapter 7: Object-oriented programming