KEMBAR78
Intro to object oriented programming.pptx
COURSE TITLE: PROGRAMMING FUNDAMENTALS
LECTURE 17
1
INTRODUCTION
Programming Fundamentals
OBJECT ORIENTED PROGRAMMING
2
Dr. Mumtaz Zahoor Programming Fundamentals
 Introduction to OOP
 Basic concepts
 Review of basic Programming concepts
 Object
 Ways to initialize object
 Class
 Constructor
 Naming Convention
Objectives
Procedural programming vs object-oriented
programming
 Procedural programming is about writing
procedures or functions that perform operations on
the data,
 Object-oriented programming is about creating
objects that contain both data and functions
Programming Fundamentals
4
Basic concepts of OOP
• Object-Oriented Programming is a
methodology to design a program using classes and
objects. It simplifies the software development and
maintenance by providing some concepts:
• Object
• Class
• Inheritance
• Polymorphism
• Abstraction
• Encapsulation
Objects
 Any entity that has state and behavior is known as an
object
 Objects are the basic run-time entities in an object-
oriented system.
 They may represent a person, a place, a bank account, a
table of data or any item that the program must handle.
 Objects take up space in the memory and have an
associated address like structure in C.
 When a program is executed the objects interact by
sending messages to one another.
Object
 An Object can be defined as an instance of a class.
Classes
 Collection of objects is called class. It is a logical entity.
 The entire set of data and code of an object can be made a
user-defined data type with the help of a class.
 Objects are variable of type class.
 Once a class has been defined we can create any number of
objects belonging to that class.
 A class is thus a collection of objects of similar type.
 Classes are user-defined data types and behave like the
built-in types of a programming language.
 A class can also be defined as a blueprint from which you
can create an individual object. Class doesn't consume any
space.
Technical contrast between Objects & Classes
CLASS OBJECT
Class is a data type Object is an instance of Class.
It generates OBJECTS It gives life to CLASS
Does not occupy memory
location
It occupies memory location.
It cannot be manipulated
because it is not available in
memory
It can be manipulated.
Encapsulation
 The wrapping up of data and functions into a single
unit 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.
 This insulation of the data from direct access by
the program is called data hiding or
information hiding.
Abstraction
 Hiding internal details and showing
functionality is known as abstraction.
 For example phone call, we don't know the
internal processing.
 In Java, we use abstract class and interface to
achieve abstraction.
Inheritance
 Inheritance provides a powerful and natural mechanism
for organizing and structuring software programs.
 When one object acquires all the properties and
behaviors of a parent object, it is known as inheritance.
 A class inherits state and behavior from its superclass.
 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.
Polymorphism
 If one task is performed by different ways, it is known as
polymorphism.
 In Java, we use method overloading and method overriding
to achieve polymorphism.
 Example of polymorphism can be to speak something; for
example, a cat speaks meow, dog barks woof, etc.
 A superclass named “Shapes” has a method called “area()”.
Subclasses of “Shapes” can be “Triangle”, “circle”,
“Rectangle”, etc. Each subclass has its way of calculating
area. Using Inheritance and Polymorphism means, the
subclasses can use the “area()” method to find the area’s
formula for that shape
What is Method Overloading
 Method overloading is the process that can
create multiple methods of the same name in
the same class, and all the methods work in
different ways. Method overloading occurs when
there is more than one method of the same
name in the class.
What is Method Overriding
 Method overriding is the process when the
subclass or a child class has the same method as
declared in the parent class.
Advantage of OOP over Procedure-oriented programming language
 1) OOPs makes development and maintenance
easier whereas in a procedure-oriented
programming language it is not easy to manage if
code grows as project size increases.
 2) OOPs provides data hiding whereas in a
procedure-oriented programming language a
global data can be accessed from anywhere.
 3) OOPs provides the ability to simulate real-world
event much more effectively. We can provide the
solution of real word problem if we are using the
Object-Oriented Programming language.
Object
 An entity that has state and behavior is known as
an object.
 State: represents the data (value) of an object.
 Behavior: represents the behavior (functionality)
of an object such as deposit, withdraw, etc.
Other Object Definitions:
 An object is a real-world entity.
 An object is a runtime entity.
 The object is an entity which has state and
behavior.
 The object is an instance of a class.
Class
 A class is a group of objects which have common
properties. It is a template or blueprint from which
objects are created. It is a logical entity. It can't be
physical.
 A class in Java can contain:
 Fields
 Methods
 Constructors
 Blocks
 Nested class and interface
Syntax to declare a class
 class class_name{
 field;
 method;
 };
Intro to object oriented  programming.pptx

Intro to object oriented programming.pptx

  • 1.
    COURSE TITLE: PROGRAMMINGFUNDAMENTALS LECTURE 17 1 INTRODUCTION Programming Fundamentals
  • 2.
    OBJECT ORIENTED PROGRAMMING 2 Dr.Mumtaz Zahoor Programming Fundamentals
  • 3.
     Introduction toOOP  Basic concepts  Review of basic Programming concepts  Object  Ways to initialize object  Class  Constructor  Naming Convention Objectives
  • 4.
    Procedural programming vsobject-oriented programming  Procedural programming is about writing procedures or functions that perform operations on the data,  Object-oriented programming is about creating objects that contain both data and functions Programming Fundamentals 4
  • 5.
    Basic concepts ofOOP • Object-Oriented Programming is a methodology to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts: • Object • Class • Inheritance • Polymorphism • Abstraction • Encapsulation
  • 6.
    Objects  Any entitythat has state and behavior is known as an object  Objects are the basic run-time entities in an object- oriented system.  They may represent a person, a place, a bank account, a table of data or any item that the program must handle.  Objects take up space in the memory and have an associated address like structure in C.  When a program is executed the objects interact by sending messages to one another. Object  An Object can be defined as an instance of a class.
  • 7.
    Classes  Collection ofobjects is called class. It is a logical entity.  The entire set of data and code of an object can be made a user-defined data type with the help of a class.  Objects are variable of type class.  Once a class has been defined we can create any number of objects belonging to that class.  A class is thus a collection of objects of similar type.  Classes are user-defined data types and behave like the built-in types of a programming language.  A class can also be defined as a blueprint from which you can create an individual object. Class doesn't consume any space.
  • 8.
    Technical contrast betweenObjects & Classes CLASS OBJECT Class is a data type Object is an instance of Class. It generates OBJECTS It gives life to CLASS Does not occupy memory location It occupies memory location. It cannot be manipulated because it is not available in memory It can be manipulated.
  • 9.
    Encapsulation  The wrappingup of data and functions into a single unit 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.  This insulation of the data from direct access by the program is called data hiding or information hiding.
  • 10.
    Abstraction  Hiding internaldetails and showing functionality is known as abstraction.  For example phone call, we don't know the internal processing.  In Java, we use abstract class and interface to achieve abstraction.
  • 11.
    Inheritance  Inheritance providesa powerful and natural mechanism for organizing and structuring software programs.  When one object acquires all the properties and behaviors of a parent object, it is known as inheritance.  A class inherits state and behavior from its superclass.  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.
  • 12.
    Polymorphism  If onetask is performed by different ways, it is known as polymorphism.  In Java, we use method overloading and method overriding to achieve polymorphism.  Example of polymorphism can be to speak something; for example, a cat speaks meow, dog barks woof, etc.  A superclass named “Shapes” has a method called “area()”. Subclasses of “Shapes” can be “Triangle”, “circle”, “Rectangle”, etc. Each subclass has its way of calculating area. Using Inheritance and Polymorphism means, the subclasses can use the “area()” method to find the area’s formula for that shape
  • 13.
    What is MethodOverloading  Method overloading is the process that can create multiple methods of the same name in the same class, and all the methods work in different ways. Method overloading occurs when there is more than one method of the same name in the class.
  • 14.
    What is MethodOverriding  Method overriding is the process when the subclass or a child class has the same method as declared in the parent class.
  • 15.
    Advantage of OOPover Procedure-oriented programming language  1) OOPs makes development and maintenance easier whereas in a procedure-oriented programming language it is not easy to manage if code grows as project size increases.  2) OOPs provides data hiding whereas in a procedure-oriented programming language a global data can be accessed from anywhere.  3) OOPs provides the ability to simulate real-world event much more effectively. We can provide the solution of real word problem if we are using the Object-Oriented Programming language.
  • 16.
    Object  An entitythat has state and behavior is known as an object.  State: represents the data (value) of an object.  Behavior: represents the behavior (functionality) of an object such as deposit, withdraw, etc.
  • 17.
    Other Object Definitions: An object is a real-world entity.  An object is a runtime entity.  The object is an entity which has state and behavior.  The object is an instance of a class.
  • 18.
    Class  A classis a group of objects which have common properties. It is a template or blueprint from which objects are created. It is a logical entity. It can't be physical.  A class in Java can contain:  Fields  Methods  Constructors  Blocks  Nested class and interface
  • 19.
    Syntax to declarea class  class class_name{  field;  method;  };

Editor's Notes

  • #7 Class data type similar to int, string etc.