Introduction to Object oriented Programming basics
SwatiAtulJoshi
9 views
18 slides
Sep 30, 2024
Slide 1 of 18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
About This Presentation
This presentation gives introduction to object oriented programming in view of ppl.
Size: 1.43 MB
Language: en
Added: Sep 30, 2024
Slides: 18 pages
Slide Content
UNIT II Object based Programming
Procedural Programming sequence of things Emphasis is on doing things i.e. procedures. share global data top-down approach Modular Programming Emphasizes separating the functionality modules perform logically discrete functions. no interaction between modules. Each module works independently Generic Programming Generic programming is about generalizing software components. Algorithms are written in terms of to-be-specified-later. In C++ class and function templates are particularly effective mechanisms.
Object-Oriented Programming decomposition of problem into a number of entities called objects Emphasis is on data rather than procedure ?? Objects have attributes and can take actions pass messages to objects, so that they take action The same message works differently for various objects A method can work appropriately with different types of data Objects can inherit traits of previously created objects Information hiding is more complete than in procedural programs New data and functions can be added easily whenever necessary. Follows bottom-up approach
Top Down approach Identify the goal or problem: The goal or problem needs to be clearly identified and measurable. Break it down into sub-goals: The sub-goals/sub-problems are what the top-up approach is all about. Solve each sub-goal/sub-problem: Using the same top-up approach, the sub-problems/sub-goals/problems are broken down into smaller manageable parts. Repeat steps 2 and 3 until the overall goal/problems are resolved: The top-up approach may involve multiple iterations.
Bottom-Up Approach Identify the components or tasks: The components or tasks need to be clearly identified and measurable. Build the system or solution: The system or solution gets its name from the fact that it is built from the individual components/tasks. Test: The system/solution needs to be tested to meet the requirements. This can be done by running a series of tests on the system/solution. Repeat steps 2 and 3: This may involve several iterations of the bottom-up approach.
Limitations of procedural programming Difficult to relate with real world objects Abstraction and modularization is difficult Difficult to understand Difficult to maintain Need of object-oriented programming Possible to map objects in the problem domain Data Hiding : Security Inheritance : Eliminate redundancy , reusability Its flexibility It makes the coding more organized Simple maintenance, an advanced analysis of complicated programs
Structured Vs OOP Structured OOP Focuses on Process Focuses on Object Follows Top Down Approach Follows Bottom Up Approach
Fundamentals of object-oriented programming objects classes data members methods messages data encapsulation data abstraction and information hiding inheritance polymorphism
Object Objects are basic run time entities. e.g. person, a place, a bank account, or any item that the program has to handle. Each object take up space in the memory to store data and code. OOP encapsulates data (attributes) and functions (behavior) into packages called objects. Objects have the property of information hiding. Representation of object
Objects Interact with each other by sending messages to each other.
Message Passing
Class A class is a blueprint or prototype that defines the data members and the methods (functions) common to all objects of a certain kind. Objects (data and functions) are members of user-defined types called classes. A class definition is an extension of a C structure definition , made up of declarations of variables and of function The variables are typically declared to be private or protected and the functions are typically declared to be public. structures members are public by default and class members are private by default.
Example : Objects and Classes Rima R002 Rita R003 Bina R004 Rani R001 class object class Student char name int rollNo setName() setRollNo() calcMarks()
Program is composed of a collection of individual units or objects , as opposed to a traditional view in which a program is a list of instructions to the computer. Data variable Member Function Data variable Member Function Data variable Member Function Object A Object B Object C
Data members Attributes of object. The variables are typically declared to be private or protected Methods or member functions or messages Functions operate on class data. functions are typically declared to be public. Defined outside or inside class. Objects communicate with each other. Encapsulation The process of binding code and data together in the form of a capsule Data is not accessible to the outside world, only those function which are wrapped in the class can access it. Since the classes use the concept of data abstraction, they are known as Abstract Data Type(ADT). EXAMPLE-tv Data Abstraction or Data Hiding The process of extracting the essential information and hiding the irrelevant details
Inheritance The feature by which one class acquires the properties and functionalities of another class Classes are extensible You can create new classes that extend or are descendents of existing classes The descendent classes can inherit all the attributes of the parent class Hierarchical classification Reusability
Inheritance
“Person” is a generalization of “Student”. “Student” is a specialization of “Person”. Person Name Gender Age Student Reg. No. Course Marks Teaching Staff Qualification Designation Specialization