Worksheet 01 - OOP
Worksheet 01 - OOP
Worksheet 01 - OOP
SESSION- 2021-22
STUDY MATERIAL
SUBJECT- COMPUTER
APPLICATIONS
CLASS- IX
Chapter -1 [ OBJECT ORIENTED PROGRAMMING ]
A class is an abstract blueprint used to create more specific, concrete objects. Classes
often represent broad categories, like Car or Dog that share attributes. These classes
define what attributes an instance of this type will have, like color, but not the value of
those attributes for a specific object.
Classes can also contain functions, called methods available only to objects of that
type. These functions are defined within the class and perform some action helpful to
that specific type of object.
For example, our Car class may have a method repaint that changes the color attribute of our
car. This function is only helpful to objects of type Car, so we declare it within the Car class
thus making it a method.
Class templates are used as a blueprint to create individual objects. These represent
specific examples of the abstract class, like myCar or goldenRetriever. Each object can have
unique values to the properties defined in the class.
For example, say we created a class, Car, to contain all the properties a car must
have, color, brand, and model. We then create an instance of a Car type object, myCar to
represent my specific car.
We could then set the value of the properties defined in the class to describe my car,
without affecting other objects or the class template.
Benefits of OOP
Let’s take a real world problem, and conceptually design an OOP software program.
Imagine running a dog sitting camp, with hundreds of pets, and you have to keep track
of the names, ages, and days attended for each pet. How would you design simple,
reusable software to model the dogs?
With hundreds of dogs, it would be inefficient to write unique code for each dog. Below
we see what that might look like with objects rufus and fluffy.
Next, we’ll take a deeper look at each of the fundamental building blocks of an OOP
program used above:
Classes
Objects
Methods
Attributes
Classes
In a nutshell, classes are essentially user defined data types. Classes are where we
create a blueprint for the structure of methods and attributes. Individual objects are
instantiated, or created from this blueprint.
Classes contain fields for attributes, and methods for behaviors. In our Dog class
example, attributes include name & birthday, while methods
include bark() and updateAttendance().
Objects
Attributes
The state of an object is defined by the data in the object’s attributes fields. For
example, a puppy and a dog might be treated differently at pet camp. The birthday
could define the state of an object, and allow the software to handle dogs of different
ages differently.
Methods
Inheritance: child classes inherit data and behaviors from parent class
Encapsulation: containing information in an object, exposing only selected
information
Abstraction: only exposing high level public methods for accessing an object
Polymorphism: many methods can do the same task
Inheritance
Inheritance allows classes to inherit features of other classes. Put another way, parent
classes extend attributes and behaviors to child classes. Inheritance supports
reusability.
If basic attributes and behaviors are defined in a parent class, child classes can be
created extending the functionality of the parent class, and adding additional attributes
and behaviors.
For example, herding dogs have the unique ability to herd animals. In other words, all
herding dogs are dogs, but not all dogs are herding dogs. We represent this difference
by creating a child class HerdingDog from the parent class Dog, and then add the
unique herd() behavior.
The benefits of inheritance are programs can create a generic parent class, and then
create more specific child classes as needed. This simplifies overall programming,
because instead of recreating the structure of the Dog class multiple times, child
classes automatically gain access to functionalities within their parent
class.
This is the same concept as the parent/child inheritance. Inheritance is from parent to
child. In our example all three dogs can bark, but only Maisel and Fluffy can herd.
Encapsulation
Encapsulation means containing all important information inside an object, and only
exposing selected information to the outside world. Attributes and behaviors are
defined by code inside the class template.
Then, when an object is instantiated from the class, the data and methods are
encapsulated in that object. Encapsulation hides the internal software code
implementation inside a class, and hides internal data of inside objects.
Let’s use a car as a metaphor for encapsulation. The information the car shares with the
outside world, using blinkers to indicate turns, are public interfaces. In contrast, the
engine is hidden under the hood.
It’s a private, internal interface. When you’re driving a car down the road, other drivers
require information to make decisions, like whether you’re turning left or right.
However, exposing internal, private data like the engine temperature, would just
confuse other drivers.
Encapsulation adds security. Attributes and methods can be set to private, so they
can’t be accessed outside the class. To get information about data in an object, public
methods & properties are used to access or update data.
This adds a layer of security, where the developer chooses what data can be seen on an
object by exposing that data through public methods in the class definition.
Within classes, most programming languages have public, protected, and private
sections. Public is the limited selection of methods available to the outside world, or
other classes within the program. Protected is only accessible to child classes.
Encapsulating & updating data: Since methods can also update an object’s data,
the developer controls what values can be changed through public methods.
This allows us to hide important information that should not be changed from both
phishing and the more likely scenario of other developers mistakenly changing
important data.
Encapsulation adds security to code and makes it easier to collaborate with external
developers. When you’re programming to share information with an external company,
you wouldn’t want to expose the classes’ templates or private data because your
company owns that intellectual property.
Instead, developers create public methods that allow other developers to call methods
on an object. Ideally, these public methods come with documentation for the external
developers.
Adds security: Only public methods and attributes are accessible from the
outside
Protects against common mistakes: Only public fields & methods
accessible, so developers don’t accidentally change something dangerous
Protects IP: Code is hidden in a class, only public methods are accessible by the
outside developers
Supportable: Most code undergoes updates and improvements
Hides complexity: No one can see what’s behind the object’s curtain!
Abstraction
Abstraction means that the user interacts with only selected attributes and methods of
an object. Abstraction uses simplified, high level tools, to access a complex object.
A driver only uses a small selection of tools: like gas pedal, brake, steering wheel,
blinker. The engineering is hidden from the driver. To make a car work, a lot of pieces
have to work under the hood, but exposing that information to the driver would be a
dangerous distraction.
Abstraction also serves an important security role. By only displaying selected pieces of
data, and only allowing data to be accessed through classes and modified through
methods, we protect the data from exposure. To continue with the car example, you
wouldn’t want an open gas tank while driving a car.
Polymorphism
Article Made
By
… Dr. Tridib Singha
PURWANCHAL VIDYAMANDIR
SESSION : 2021-2022
CLASS : IX
SUBJECT : COMPUTER APPLICATIONS
[ WORKSHEET : 1 ]
Q3. Name the term respect to Object Oriented Programming concepts :--
a. The property of decomposing a system into a set of cohesive and loosely coupled
modules .
b. The Object Oriented property support reusability and its transitive in nature .
c. A class inheriting features of another class and adding its unique features .
d. The act can be performed in multiple ways by object and subclasses of a class.