OOP Concepts Created by - Om Vikram Thapa
OOP vs. POP Emphasis is on data. Divides code into logical chunks individuals of a team can be experts in, and outsiders can understand via interfaces  Supports code evolution: internals can always be re-written as long as interface stays the same. Data security. Emphasis is on procedures. This programming technique can only be used in a very small program. if the same statement sequence is needed at different locations, the sequence must be copied. If an error needed to be modified, every copy needs to be modified.
Procedure Program view Main Program Data Procedure 1 Procedure 2 Procedure 3
OOP Program view Data Object 3 Data 3  +   Procedures 3 Object 2 Data 2  +   Procedures 2  Object 4 Data 4  +   Procedures 4 Object 1 Data 1 +Procedures 1
Main OOP Concepts: Object Class Abstraction  Encapsulation Inheritance Polymorphism
Objects and Class An  object  represents something with which we can interact in a program A class represents a concept, and an object represents the embodiment of a class A class is a blueprint for an object. A class can be used to create multiple objects A program models a world of interacting objects. Objects create other objects and “send messages” to each other. Each object belongs to a class; a class defines properties of its objects.  The data type of an object is its class.
Abstraction One of the chief advantages of object-oriented programming is the idea that programmers can essentially focus on the “big picture” and ignore specific details regarding the inner-workings of an object. This concept is called  abstraction .
Encapsulation Abstraction in OOP is closely related to a concept called  encapsulation .  Data and the ways to get at that data are wrapped in a single package, a class. The only way to access such data is through that package. This idea translates to information hiding.
Inheritance Another of the main tenets of OOP is  inheritance . Inheritance allows programmers to create new classes from existing ones. A child class inherits its properties and attributes from its parents, which programmers can change.
Polymorphism Polymorphism describes how programmers write methods to do some general purpose function.  Different objects might perform polymorphic methods differently. The ability of objects to respond differently to the same message or function call.
Examples Object legislates how its data may be accessed ( encapsulation ) Once you have created an ADT for complex numbers, say Complex, you can use it in the same way like well-known data types such as integers. Encapsulation provides a way to protect data from accidental corruption. One class may be a special case of another ( inheritance ) Rectangle is like a square, plus a second (possibly) distinct value Colored-Rectangle is like a rectangle, plus the concept of color Different classes in a hierarchy behave correctly( polymorphism ) shape.getArea(a,b) = len*wid, if shape is a rectangle shape.getArea(a) = PI*r2, if shape is a circle

OOP

  • 1.
    OOP Concepts Createdby - Om Vikram Thapa
  • 2.
    OOP vs. POPEmphasis is on data. Divides code into logical chunks individuals of a team can be experts in, and outsiders can understand via interfaces Supports code evolution: internals can always be re-written as long as interface stays the same. Data security. Emphasis is on procedures. This programming technique can only be used in a very small program. if the same statement sequence is needed at different locations, the sequence must be copied. If an error needed to be modified, every copy needs to be modified.
  • 3.
    Procedure Program viewMain Program Data Procedure 1 Procedure 2 Procedure 3
  • 4.
    OOP Program viewData Object 3 Data 3 + Procedures 3 Object 2 Data 2 + Procedures 2 Object 4 Data 4 + Procedures 4 Object 1 Data 1 +Procedures 1
  • 5.
    Main OOP Concepts:Object Class Abstraction Encapsulation Inheritance Polymorphism
  • 6.
    Objects and ClassAn object represents something with which we can interact in a program A class represents a concept, and an object represents the embodiment of a class A class is a blueprint for an object. A class can be used to create multiple objects A program models a world of interacting objects. Objects create other objects and “send messages” to each other. Each object belongs to a class; a class defines properties of its objects. The data type of an object is its class.
  • 7.
    Abstraction One ofthe chief advantages of object-oriented programming is the idea that programmers can essentially focus on the “big picture” and ignore specific details regarding the inner-workings of an object. This concept is called abstraction .
  • 8.
    Encapsulation Abstraction inOOP is closely related to a concept called encapsulation . Data and the ways to get at that data are wrapped in a single package, a class. The only way to access such data is through that package. This idea translates to information hiding.
  • 9.
    Inheritance Another ofthe main tenets of OOP is inheritance . Inheritance allows programmers to create new classes from existing ones. A child class inherits its properties and attributes from its parents, which programmers can change.
  • 10.
    Polymorphism Polymorphism describeshow programmers write methods to do some general purpose function. Different objects might perform polymorphic methods differently. The ability of objects to respond differently to the same message or function call.
  • 11.
    Examples Object legislateshow its data may be accessed ( encapsulation ) Once you have created an ADT for complex numbers, say Complex, you can use it in the same way like well-known data types such as integers. Encapsulation provides a way to protect data from accidental corruption. One class may be a special case of another ( inheritance ) Rectangle is like a square, plus a second (possibly) distinct value Colored-Rectangle is like a rectangle, plus the concept of color Different classes in a hierarchy behave correctly( polymorphism ) shape.getArea(a,b) = len*wid, if shape is a rectangle shape.getArea(a) = PI*r2, if shape is a circle