Professional Documents
Culture Documents
Assignment 1: BY: Umair Khalid Khan 337959 BSCS10 A
Assignment 1: BY: Umair Khalid Khan 337959 BSCS10 A
The first one would be that real life scenarios are much easier to represent in OOP. For
example, a Car can be a user defined class, which has several attributes (data members)
like model, year, registration number, etc. and certain methods to set these attributes.
Similarly another example can be of a cuboid, whose dimensions can be stored as data
members and methods can be defined to use those dimensions, such as a method that
calculates and returns the volume of the cuboid.
Security, OOP provides a more secure environment as data members may be not be
allowed to be directly accessible, certain methods would be required to access and
modify data members, eliminating accidental changes to data and hence, ensuring data
integrity. This bundling of data and methods is called encapsulation.
Encapsulation makes your code easier to debug and maintain as the data members and
methods are collected together, which makes finding flaws easier as you would not have
to go back and forth in your code.
Reusability of code. The ability of inheritance in OOP provides coders to re-use their
existing code without changing it and simply adding sub classes. When a higher level
class is further categorised in a sub class all upper class data members and methods are
also available for the lower class. This way you can accommodate ‘new’ objects that
differ slightly from the current design. This can be explained via a grocery store. Where
all ‘objects’ would have a price and a serial number, but can be furthered divided into
categories like food, utilities, stationary, etc. Therefore, by extension the categories have
some properties not shared by other categories. This concept can be applied to
software’s as well, as you can share your code without needing to make major changes.
All of the above mentioned benefits lead to more positive outcomes like increased
productivity (modular design that can be divided), easy to maintain code, high quality
software with lower costs and faster development, separates interface and implementation.