T_2_KEY OR BASIC CONCEPT OF OOP
T_2_KEY OR BASIC CONCEPT OF OOP
Class
Object
CONCEPT
Encapsulation
OF
OOPS Polymorphism
Abstraction
Inheritence
CLASS
• A class is grouping of objects that have the identical properties, common behavior
and shared relationship.
• A class binds the data and its related functions together.
• A Class is a user-defined data type that has data members and member functions.
• Data members are the data variables and member functions are the functions used
to manipulate these variables together these data members and member functions
define the properties and behavior of the objects in a Class.
• The Entire group of data and code of an object can be built as a user-defined data
type using class.
• Objects are nothing but variable of type class.
• Once a class has been declared, the programmer can create a number of objects
associated with that class.
• A class is also called a model.
• Every object has its own value for each of its member variables.
OBJECT
• Objects are primary run-time entities in OOP.
• It is also instance of a class
• Every object has its own properties of features that illustrate what the object can
do.
• It can be singly recognized by its name.
• It declares the state that is shown by the data values of its characteristic at a specific
time. The state of the object varies according to the procedure used with it. It is
called as the action of the object.
• No memory is allocated but when an object is defined, memory is allocated.
• The action of the object depends up on the member function defined within its class.
Object : signup
Data :
First_Name_of_user
Last_name_of_user
Password
Confirm_password
Emai_id
Functions :
register
login
• The name of the object is signup. its data members are fist_name_of_user,
password , email_id.
• The various functions associated with the signup are register and login.
ENCAPSULATION
• The packing of data and functions into a single component is known as
encapsulation.
• It can be achieved by making the data members' scope private and the member
function’s scope public to access these data members.
• Encapsulation makes the data non-accessible to the outside world. The benefits of
encapsulation include.
Example-1:
o A person at the same time can have different characteristics. A man at the same
time is a father, a husband, and an employee. So the same person possesses
different behavior in different situations. This is called polymorphism.
Example-2:
o In above example suppose we have to write a function to area() for all shapes ,
sometimes there are 2 properties, and sometimes there are 3 properties . We can
write the area () Method with the same name having different formulas; the
concerned method will be called according to parameters.
INHERITANCE
o Inheritance is the method by which objects of one class get the properties of objects
of another class.
o The class which inherits the features is known as the child class, and the class whose
features it inherited is called the parent class. The benefits of Inheritance include.
o Code Reusability: Inheritance allows classes to inherit properties and
behavior from a base class, promoting code reuse. Derived classes can extend
and specialize the functionality of the base class, eliminating the need to
rewrite common code.
o Polymorphism: Inheritance enables polymorphism, where objects of derived
classes can be treated as objects of their base class. This allows for more
flexible and dynamic programming, as different derived classes can be used
interchangeably through a common interface.
o Hierarchical Organization: Inheritance establishes a hierarchical relationship
among classes, reflecting real-world or conceptual hierarchies. This improves
code organization, understandability, and maintainability by representing
relationships and dependencies in a structured manner.
o In above example, Class Vehicle is the parent class, and Class Bus, Car, and Bike are child
classes and they are reusing the common feature (include wheels) this is called inheritance.
ABSTRACTION
o Abstraction means displaying only essential information and hiding the details.
o Data abstraction refers to providing only essential information about the data to the
outside world(private variables), hiding the background details or implementation.
o Abstraction is the idea of using a simple interface to access functionality without
needing to know the underlying details.
Here are some examples of abstraction in everyday life:
Driving a car
• You can drive a car without needing to know how the engine works. You only need
to know how to turn the key or press the start button. What all components your
car has. The car internal implementation and complex logic is completely hidden
from the user.
Making coffee
• You only need to know how to add water and coffee beans, turn on the coffee
maker, and select the type of coffee you want. You don't need to know how the
coffee maker works internally.
Using an ATM
• You can perform functions like withdrawing cash, depositing cash, checking your
balance, or printing bills. You don't need to see how the ATM performs these
actions.
In programming, abstraction is used to hide complex details behind simple procedures. This
makes it easier for other developers to use the code.
ATM
MACHINE
• In above example we all use an ATM machine for cash withdrawal , cash deposit ,
money transfer , balance info , mini-statement,etc,. in our daily life.
• But we don’t know internally what things are happening inside ATM machine when
you insert an ATM card for performing any kind of operation.