Introduction to OOPs
Concepts
2
What is Object-oriented?
• One of the key challenges faced by Computer Scientist is how
to handle complexity.
• Two main concepts used to manage complexity are Modularity
and Abstractions.
– Modularity means breaking a large system up into smaller
pieces until each peace becomes simple enough to be
handled easily.
– Abstraction means hiding implementation details in a
module and providing a well-defined interface through
which the functionality of the module can be accessed by
other modules. Thus, each module in a system is treated as
a “black box” by other modules.
– Object-oriented programming provides both the facilities.
3
What is an Object?
• An Object is a software entity that models something in the real world. It
has two main properties:
– State: the object encapsulates information about itself - attributes or
fields.
– Behaviour: the object can do some things on behalf of other objects –
methods
• Example: In a banking system, a particular bank account is an example of
an object.
– Its state consists of attributes like: owner, account number, balance.
– Its behaviours consist of: deposit, withdraw, etc.
• Other examples of objects are:
– myself – an instructor object. What are my fields and methods?
– you – a student object
– this room – a room object
– this university, car, etc.
• In an object-oriented system, objects are created from something called a
Class.
4
What is a class?
• A class is a general, abstract representation of an object, that specifies the
fields and methods that such an object has.
• When we write OO programs we don't define individual objects, we define
classes, and then use them as templates for constructing objects.
• Each individual object is called an instance of its class.
• When a class is defined, no memory is allocated but when it is instantiated
(i.e. an object is created) memory is allocated.
• For example, you might have a Tree class that describes the features of all
trees (each tree has branches and roots, grows, etc.).
• The Tree class serves as an abstract model for the concept of a tree.
• Of course, once you have a Tree class, you can create lots of different
instances of that tree, and each different tree instance can have different
features (it can be short, tall, bushy, have fruits, etc), yet still behave like a
tree and can be recognized as one.
5
What is a class?
Accessing data members and member functions: The data members and member functions of class can be
accessed using the dot(‘.’) operator with the object. For example if the name of object is obj and you want to
access the member function with the name printName() then you will have to write obj.printName() .
6
What is a class?
7
Data Abstraction and Encapsulation
• The wrapping up of data and function into a single unit
(called class) is known as encapsulation.
• The data is not accessible to the outside world, and only those
functions which are wrapped in the class can access it.
• These functions provide the interface between the object’s
data and the program.
• This insulation of the data from direct access by the program
is called data hiding or information hiding.
8
Data Abstraction and Encapsulation
• Abstraction refers to the act of representing essential features
without including the background details or explanation.
• Classes use the concept of abstraction and are defined as a list
of abstract attributes such as size, wait, and cost, and function
operate on these attributes.
• They encapsulate all the essential properties of the object that
are to be created.
• The attributes are some time called data members because
they hold information.
• The functions that operate on these data are sometimes called
methods or member function.
9
Data Abstraction and Encapsulation
10
Inheritance
• The capability of a class to derive properties and characteristics
from another class is called Inheritance.
Sub Class: The class that inherits properties from another class is called Sub class or
Derived Class.
Super Class: The class whose properties are inherited by sub class is called Base Class
or Super class.
11
Inheritance
• In OOP, the concept of inheritance provides the idea of
reusability.
• This means that we can add additional features to an existing
class without modifying it.
• This is possible by deriving a new class from the existing one.
• The new class will have the combined feature of both the
classes.
• The real appeal and power of the inheritance mechanism is that
it allows the programmer to reuse a class i.e almost, but not
exactly, what he wants, and to tailor the class in such a way that
it does not introduced any undesirable side-effects into the rest
of classes.
12
Polymorphism
• Polymorphism, means the ability to take more than one form.
• An operation may exhibit different behavior is different
instances.
• The behavior depends upon the types of data used in the
operation.
For example,
• The process of making an operator to exhibit different
behaviors in different instances is known as operator
overloading.
• Consider the operation of addition (+). For two numbers, the
operation + will generate a sum.
• If the operands are strings, then the operation + would produce a
third string by concatenation.
13
Polymorphism
• Polymorphism plays an important role in allowing objects
having different internal structures to share the same external
interface.
• This means that a general class of operations may be accessed
in the same manner even though specific action associated with
each operation may differ.
14
Benefits of OOP
• Through inheritance, we can eliminate redundant code extend
the use of existing Classes.
• We can build programs from the standard working modules that
communicate with one another, rather than having to start
writing the code from scratch.
• This leads to saving of development time and higher
productivity.
• The principle of data hiding helps the programmer to build
secure program that can not be invaded by code in other parts
of a programs.
• Object-oriented system can be easily upgraded from small to
large system.
• Software complexity can be easily managed.

L1-Introduction to OOPs concepts.pdf

  • 1.
  • 2.
    2 What is Object-oriented? •One of the key challenges faced by Computer Scientist is how to handle complexity. • Two main concepts used to manage complexity are Modularity and Abstractions. – Modularity means breaking a large system up into smaller pieces until each peace becomes simple enough to be handled easily. – Abstraction means hiding implementation details in a module and providing a well-defined interface through which the functionality of the module can be accessed by other modules. Thus, each module in a system is treated as a “black box” by other modules. – Object-oriented programming provides both the facilities.
  • 3.
    3 What is anObject? • An Object is a software entity that models something in the real world. It has two main properties: – State: the object encapsulates information about itself - attributes or fields. – Behaviour: the object can do some things on behalf of other objects – methods • Example: In a banking system, a particular bank account is an example of an object. – Its state consists of attributes like: owner, account number, balance. – Its behaviours consist of: deposit, withdraw, etc. • Other examples of objects are: – myself – an instructor object. What are my fields and methods? – you – a student object – this room – a room object – this university, car, etc. • In an object-oriented system, objects are created from something called a Class.
  • 4.
    4 What is aclass? • A class is a general, abstract representation of an object, that specifies the fields and methods that such an object has. • When we write OO programs we don't define individual objects, we define classes, and then use them as templates for constructing objects. • Each individual object is called an instance of its class. • When a class is defined, no memory is allocated but when it is instantiated (i.e. an object is created) memory is allocated. • For example, you might have a Tree class that describes the features of all trees (each tree has branches and roots, grows, etc.). • The Tree class serves as an abstract model for the concept of a tree. • Of course, once you have a Tree class, you can create lots of different instances of that tree, and each different tree instance can have different features (it can be short, tall, bushy, have fruits, etc), yet still behave like a tree and can be recognized as one.
  • 5.
    5 What is aclass? Accessing data members and member functions: The data members and member functions of class can be accessed using the dot(‘.’) operator with the object. For example if the name of object is obj and you want to access the member function with the name printName() then you will have to write obj.printName() .
  • 6.
  • 7.
    7 Data Abstraction andEncapsulation • The wrapping up of data and function into a single unit (called class) is known as encapsulation. • The data is not accessible to the outside world, and only those functions which are wrapped in the class can access it. • These functions provide the interface between the object’s data and the program. • This insulation of the data from direct access by the program is called data hiding or information hiding.
  • 8.
    8 Data Abstraction andEncapsulation • Abstraction refers to the act of representing essential features without including the background details or explanation. • Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, wait, and cost, and function operate on these attributes. • They encapsulate all the essential properties of the object that are to be created. • The attributes are some time called data members because they hold information. • The functions that operate on these data are sometimes called methods or member function.
  • 9.
  • 10.
    10 Inheritance • The capabilityof a class to derive properties and characteristics from another class is called Inheritance. Sub Class: The class that inherits properties from another class is called Sub class or Derived Class. Super Class: The class whose properties are inherited by sub class is called Base Class or Super class.
  • 11.
    11 Inheritance • In OOP,the concept of inheritance provides the idea of reusability. • This means that we can add additional features to an existing class without modifying it. • This is possible by deriving a new class from the existing one. • The new class will have the combined feature of both the classes. • The real appeal and power of the inheritance mechanism is that it allows the programmer to reuse a class i.e almost, but not exactly, what he wants, and to tailor the class in such a way that it does not introduced any undesirable side-effects into the rest of classes.
  • 12.
    12 Polymorphism • Polymorphism, meansthe ability to take more than one form. • An operation may exhibit different behavior is different instances. • The behavior depends upon the types of data used in the operation. For example, • The process of making an operator to exhibit different behaviors in different instances is known as operator overloading. • Consider the operation of addition (+). For two numbers, the operation + will generate a sum. • If the operands are strings, then the operation + would produce a third string by concatenation.
  • 13.
    13 Polymorphism • Polymorphism playsan important role in allowing objects having different internal structures to share the same external interface. • This means that a general class of operations may be accessed in the same manner even though specific action associated with each operation may differ.
  • 14.
    14 Benefits of OOP •Through inheritance, we can eliminate redundant code extend the use of existing Classes. • We can build programs from the standard working modules that communicate with one another, rather than having to start writing the code from scratch. • This leads to saving of development time and higher productivity. • The principle of data hiding helps the programmer to build secure program that can not be invaded by code in other parts of a programs. • Object-oriented system can be easily upgraded from small to large system. • Software complexity can be easily managed.