CHAPTER 1 INTRODUCTION TO THE OOP PARADIGM
Introduction • Object Oriented Programming (OOP) • Structured Programming • Programming paradigm is a fundamental style of computer programming
• Object Oriented Programming (OOP) • Structured Programming • Programming paradigm is a fundamental style of computer programming Introduction
• Programming paradigms differ in how each element of the programs is represented and how steps are defined for solving problems. • OOP focuses on representing problems using real-world objects and their behaviour, while Structured Programming deals with organizing the program in a logical structure. Introduction
• A structured program is made up of simple program flow structures, which are hierarchically organized. • They are Sequence, Selection And Repetition. What is Structured/ Procedural Programming?
• thinking about the problem to be solved in terms of real- world elements and representing the problem in terms of objects and their behaviour • Classes depict the abstract representations of real world objects What is Object Oriented Programming?
• Classes have properties called attributes. • Attributes are implemented as global and instance variables. • Methods in the classes represent or define the behaviour of these classes. • Methods and attributes of classes are called the members of the class. • An instance of a class is called an object. What is Object Oriented Programming?
There are several important OOP concepts such as • Data abstraction, • Encapsulation, • Polymorphism, • Messaging, • Modularity and • Inheritance. What is Object Oriented Programming?
What is Object Oriented Programming? Structured/Procedural Programming Object Oriented Programming Structured Programming is designed which focuses on process/ logical structure and then data required for that process. Object Oriented Programming is designed which focuses on data. Structured programming follows top-down approach. Object oriented programming follows bottom-up approach. Structured Programming is also known as Modular Programming and a subset of procedural programming language. Object Oriented Programming supports inheritance, encapsulation, abstraction, polymorphism, etc. In Structured Programming, Programs are divided into small self-contained functions. In Object Oriented Programming, Programs are divided into small entities called objects. Structured Programming is less secure as there is no way of data hiding. Object Oriented Programming is more secure as having data hiding feature. Structured Programming can solve moderately complex programs. Object Oriented Programming can solve any complex programs. Structured Programming provides less reusability, more function dependency. Object Oriented Programming provides more reusability, less function dependency. Less abstraction and less flexibility. More abstraction and more flexibility.
• OOP allow decomposition of a problem into a number of entities called Object and then builds data and function around these objects. The data of the objects can be accessed only by the functions associated with that object. The functions of one object can access the functions of other object. OOPs Basic concepts
• Class is a blueprint of an object that contains variables for storing data and functions to performing operations on these data. • Class will not occupy any memory space and hence it is only logical representation of data. class Employee { } OOPs Basic concepts…Class:
• Objects are the basic run-time entities in an object oriented system. They may represent a person, a place or any item that the program has to handle. • "Object is a Software bundle of related variable and methods." • “Object is an instance of a class” OOPs Basic concepts…Object:
OOPs Basic concepts…Object:
• Class will not occupy any memory space. Hence to work with the data represented by the class you must create a variable for the class, which is called as an object. OOPs Basic concepts…Object:
• When an object is created by using the keyword new, then memory will be allocated for the class in heap memory area, which is called as an instance and its starting address will be stored in the object in stack memory area. • When an object is created without the keyword new, then memory will not be allocated in heap i.e. instance will not be created and object in the stack contains the value null. OOPs Basic concepts…Object:
• When an object contains null, then it is not possible to access the members of the class using that object. class Employee { } • Syntax to create an object of class Employee:- Employee objEmp = new Employee(); OOPs Basic concepts…Object:
• Abstraction • Encapsulation • Inheritance • Polymorphism OOPs Basic concepts…
• Abstraction is "To represent the essential feature without representing the back ground details." • Abstraction lets you focus on what the object does instead of how it does it. • Abstraction provides you a generalized view of your classes or object by providing relevant information. • Abstraction is the process of hiding the working style of an object, and showing the information of an object in understandable manner. OOPs Basic concepts…Abstraction
• Real world Example of Abstraction: - • Suppose you have an object Mobile Phone. • Suppose you have 3 mobile phones as following:- Nokia 1400 (Features:- Calling, SMS) Nokia 2700 (Features:- Calling, SMS, FM Radio, MP3, Camera) Black Berry (Features:-Calling, SMS, FM Radio, MP3, Camera, Video Recording, Reading E-mails) OOPs Basic concepts…Abstraction
Abstract information (Necessary and Common Information) for the object "Mobile Phone" is make a call to any number and can send SMS." So that, for mobile phone object you will have abstract class like following:- OOPs Basic concepts…Abstraction abstract class MobilePhone { public void Calling(); public void SendSMS(); } public class Nokia1400 : MobilePhone { } public class Nokia2700 : MobilePhone { public void FMRadio(); public void MP3(); public void Camera(); } public class BlackBerry : MobilePhone { public void FMRadio(); public void MP3(); public void Camera(); public void Recording(); public void ReadAndSendEmails(); }
• Wrapping up data member and method together into a single unit (i.e. Class) is called Encapsulation. • That is enclosing the related operations and data related to an object into that object. OOPs Basic concepts…Encapsulation class Teacher { int id; string name; void teaching(); }
class Demo { private int mark; public int Mark { get { return mark; } set { if (mark > 0) mark = value; else _mark = 0; } } } OOPs Basic concepts…Encapsulation
• When a class acquire the property of another class is known as inheritance. • Inheritance is process of object reusability. OOPs Basic concepts…Inheritance
OOPs Basic concepts…Inheritance public class ParentClass { public ParentClass() { Console.WriteLine("Parent Constructor."); } public void print() { Console.WriteLine("I'm a Parent Class."); } } public class ChildClass : ParentClass { public ChildClass() { Console.WriteLine("Child Constructor."); } public static void Main() { ChildClass child = new ChildClass(); child.print(); } }
• Polymorphism means one name many forms. • One function behaves different forms. . • In other words, "Many forms of a single object is called Polymorphism." OOPs Basic concepts…Polymorphism
Difference between Abstraction and Encapsulation Abstraction Encapsulation 1. Abstraction solves the problem in the design level. 1. Encapsulation solves the problem in the implementation level. 2. Abstraction is used for hiding the unwanted data and giving relevant data. 2. Encapsulation means hiding the code and data into a single unit to protect the data from outside world. 3. Abstraction lets you focus on what the object does instead of how it does it 3. Encapsulation means hiding the internal details or mechanics of how an object does something. 4. Abstraction- Outer layout, used in terms of design. For Example:- Outer Look of a Mobile Phone, like it has a display screen and keypad buttons to dial a number. 4. Encapsulation- Inner layout, used in terms of implementation. For Example:- Inner Implementation detail of a Mobile Phone, how keypad button and Display Screen are connect with each other using circuits.

introduction of Object oriented programming

  • 1.
    CHAPTER 1 INTRODUCTION TOTHE OOP PARADIGM
  • 2.
    Introduction • Object OrientedProgramming (OOP) • Structured Programming • Programming paradigm is a fundamental style of computer programming
  • 3.
    • Object OrientedProgramming (OOP) • Structured Programming • Programming paradigm is a fundamental style of computer programming Introduction
  • 4.
    • Programming paradigmsdiffer in how each element of the programs is represented and how steps are defined for solving problems. • OOP focuses on representing problems using real-world objects and their behaviour, while Structured Programming deals with organizing the program in a logical structure. Introduction
  • 5.
    • A structuredprogram is made up of simple program flow structures, which are hierarchically organized. • They are Sequence, Selection And Repetition. What is Structured/ Procedural Programming?
  • 6.
    • thinking aboutthe problem to be solved in terms of real- world elements and representing the problem in terms of objects and their behaviour • Classes depict the abstract representations of real world objects What is Object Oriented Programming?
  • 7.
    • Classes haveproperties called attributes. • Attributes are implemented as global and instance variables. • Methods in the classes represent or define the behaviour of these classes. • Methods and attributes of classes are called the members of the class. • An instance of a class is called an object. What is Object Oriented Programming?
  • 8.
    There are severalimportant OOP concepts such as • Data abstraction, • Encapsulation, • Polymorphism, • Messaging, • Modularity and • Inheritance. What is Object Oriented Programming?
  • 9.
    What is ObjectOriented Programming? Structured/Procedural Programming Object Oriented Programming Structured Programming is designed which focuses on process/ logical structure and then data required for that process. Object Oriented Programming is designed which focuses on data. Structured programming follows top-down approach. Object oriented programming follows bottom-up approach. Structured Programming is also known as Modular Programming and a subset of procedural programming language. Object Oriented Programming supports inheritance, encapsulation, abstraction, polymorphism, etc. In Structured Programming, Programs are divided into small self-contained functions. In Object Oriented Programming, Programs are divided into small entities called objects. Structured Programming is less secure as there is no way of data hiding. Object Oriented Programming is more secure as having data hiding feature. Structured Programming can solve moderately complex programs. Object Oriented Programming can solve any complex programs. Structured Programming provides less reusability, more function dependency. Object Oriented Programming provides more reusability, less function dependency. Less abstraction and less flexibility. More abstraction and more flexibility.
  • 10.
    • OOP allowdecomposition of a problem into a number of entities called Object and then builds data and function around these objects. The data of the objects can be accessed only by the functions associated with that object. The functions of one object can access the functions of other object. OOPs Basic concepts
  • 11.
    • Class isa blueprint of an object that contains variables for storing data and functions to performing operations on these data. • Class will not occupy any memory space and hence it is only logical representation of data. class Employee { } OOPs Basic concepts…Class:
  • 12.
    • Objects arethe basic run-time entities in an object oriented system. They may represent a person, a place or any item that the program has to handle. • "Object is a Software bundle of related variable and methods." • “Object is an instance of a class” OOPs Basic concepts…Object:
  • 13.
  • 14.
    • Class willnot occupy any memory space. Hence to work with the data represented by the class you must create a variable for the class, which is called as an object. OOPs Basic concepts…Object:
  • 15.
    • When anobject is created by using the keyword new, then memory will be allocated for the class in heap memory area, which is called as an instance and its starting address will be stored in the object in stack memory area. • When an object is created without the keyword new, then memory will not be allocated in heap i.e. instance will not be created and object in the stack contains the value null. OOPs Basic concepts…Object:
  • 16.
    • When anobject contains null, then it is not possible to access the members of the class using that object. class Employee { } • Syntax to create an object of class Employee:- Employee objEmp = new Employee(); OOPs Basic concepts…Object:
  • 17.
    • Abstraction • Encapsulation •Inheritance • Polymorphism OOPs Basic concepts…
  • 18.
    • Abstraction is"To represent the essential feature without representing the back ground details." • Abstraction lets you focus on what the object does instead of how it does it. • Abstraction provides you a generalized view of your classes or object by providing relevant information. • Abstraction is the process of hiding the working style of an object, and showing the information of an object in understandable manner. OOPs Basic concepts…Abstraction
  • 19.
    • Real worldExample of Abstraction: - • Suppose you have an object Mobile Phone. • Suppose you have 3 mobile phones as following:- Nokia 1400 (Features:- Calling, SMS) Nokia 2700 (Features:- Calling, SMS, FM Radio, MP3, Camera) Black Berry (Features:-Calling, SMS, FM Radio, MP3, Camera, Video Recording, Reading E-mails) OOPs Basic concepts…Abstraction
  • 20.
    Abstract information (Necessaryand Common Information) for the object "Mobile Phone" is make a call to any number and can send SMS." So that, for mobile phone object you will have abstract class like following:- OOPs Basic concepts…Abstraction abstract class MobilePhone { public void Calling(); public void SendSMS(); } public class Nokia1400 : MobilePhone { } public class Nokia2700 : MobilePhone { public void FMRadio(); public void MP3(); public void Camera(); } public class BlackBerry : MobilePhone { public void FMRadio(); public void MP3(); public void Camera(); public void Recording(); public void ReadAndSendEmails(); }
  • 21.
    • Wrapping updata member and method together into a single unit (i.e. Class) is called Encapsulation. • That is enclosing the related operations and data related to an object into that object. OOPs Basic concepts…Encapsulation class Teacher { int id; string name; void teaching(); }
  • 22.
    class Demo { private intmark; public int Mark { get { return mark; } set { if (mark > 0) mark = value; else _mark = 0; } } } OOPs Basic concepts…Encapsulation
  • 23.
    • When aclass acquire the property of another class is known as inheritance. • Inheritance is process of object reusability. OOPs Basic concepts…Inheritance
  • 24.
    OOPs Basic concepts…Inheritance publicclass ParentClass { public ParentClass() { Console.WriteLine("Parent Constructor."); } public void print() { Console.WriteLine("I'm a Parent Class."); } } public class ChildClass : ParentClass { public ChildClass() { Console.WriteLine("Child Constructor."); } public static void Main() { ChildClass child = new ChildClass(); child.print(); } }
  • 25.
    • Polymorphism meansone name many forms. • One function behaves different forms. . • In other words, "Many forms of a single object is called Polymorphism." OOPs Basic concepts…Polymorphism
  • 26.
    Difference between Abstractionand Encapsulation Abstraction Encapsulation 1. Abstraction solves the problem in the design level. 1. Encapsulation solves the problem in the implementation level. 2. Abstraction is used for hiding the unwanted data and giving relevant data. 2. Encapsulation means hiding the code and data into a single unit to protect the data from outside world. 3. Abstraction lets you focus on what the object does instead of how it does it 3. Encapsulation means hiding the internal details or mechanics of how an object does something. 4. Abstraction- Outer layout, used in terms of design. For Example:- Outer Look of a Mobile Phone, like it has a display screen and keypad buttons to dial a number. 4. Encapsulation- Inner layout, used in terms of implementation. For Example:- Inner Implementation detail of a Mobile Phone, how keypad button and Display Screen are connect with each other using circuits.