Nothing Special   »   [go: up one dir, main page]

8.basic Concepts of OOPS

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

CST205 OBJECT ORIENTED PROGRAMMING

USING JAVA
MODULE 1
BASIC OBJECT ORIENTED CONCEPTS
Basic Object Oriented Concepts
 Object-Oriented Programming (OOP) is the term used to describe a programming
approach based on objects and classes.
 The Object –Oriented Paradigm allows us to organise software as a collection of objects

that consist of both data and behaviour.


 In OOD, implementation of a software is based on the concepts of objects.
 This approach is very close to the real-world applications
Object
● An object is an instance of a class ● Objects are real-world entities that has
their own state and behavior.
● An object has physical existence. Object is a complex datatype that has an identity,
contains other datatypes, called attributes and modules of code called operations or
methods.
Attributes and associated values are hidden inside the object.
Any object that wants to obtain or change a value associated with other object ,must do
so by sending a message to one of the objects(invoking a method).
CLASS
A class is a blueprint or prototype from which objects are created
 A class is a generalized description of an object. No physical existence.
 Acts as a type or category
 Classes are templates that have methods and attribute names and type

information ,but no actual values. Objects are generated by these classes


and they actually contain values.
 When the system is running objects are created by classes as they are

needed to contain state information.


 When objects are no longer needed by the application, they are eliminated.

Example:
 Let’s take Student as a class. James is an instance / object of the class

Student
 Object has a physical existence while a class is just a logical definition .
Another Example-Class
Abstraction
Abstraction means displaying only essential information and hiding the internal
details.
● It is a process of generalizing things at design level.
● Data abstraction refers to providing only essential information about the data
to the outside world, hiding the background details or implementation.
● Consider a real-life example of a man driving a car. The man only knows that
pressing the accelerators will increase the speed of the car or applying brakes
will stop the car.● All about showing necessary details.
Encapsulation
 The wrapping up of data(variables) and functions (methods) that operates on the data,
 into a single unit (called class) is known as encapsulation.
 ● It is also called "information hiding“, hides the internal representation, or state, of an
 object from the outside through access modifies (Private / Public).
 ● Hiding unnecessary details, at implementation level.
Protection of data from accidental corruption, by means of access specifiers (Private /
Public), it provides security.
• Flexibility and extensibility of the code and reduction in complexity
• Encapsulation of a class can hide the internal details of how an object does something
• Encapsulation protects abstraction
Inheritance
 The capability of a class to derive properties and characteristics from another class is
called Inheritance.
 Inheritance is the process by which objects of one class acquired the properties of

objects of another classes


 Base Class : The class whose properties are inherited by subclass is called Base Class or

Super class.
 Derived Class : The class that inherits properties from another class is called Subclass or

Derived Class.
Inheritance
Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to create
a new class and there is already a class that includes some of the code that we want, we
can derive our new class from the existing class. By doing this, we are reusing the fields
and methods of the existing class.
Polymorphism
The word polymorphism means having many forms.
● Refers to a programming language's ability to process objects differently depending on
their data type or class
● An operation may exhibit different behaviors in different instances. The behavior
depends upon the types of data used in the operation.
● Ability for objects of different classes related by inheritance to respond differently to
the same member function call
 Static polymorphism: the binding between the method call an the method body
happens at the time of compilation and, this binding is known as static binding or early
binding
 ● Runtime polymorphism or Dynamic Method Dispatch is a process in which a call to an
 overridden method is resolved at runtime.
 ● Dynamic binding happens when all information needed for a function call cannot be
 determined at compile-time(Dynamic Binding or Late Binding)
 ● In the example, same rotation of steering wheel causes, different mechanical

operations, corresponding to the steering type present in each cars.


 ● Brings flexibility to the implementations
 + operator used for addition and concatenation

You might also like