Object Oriented Programming Introduction to Object Oriented Language
Object Oriented Programming Introduction to Object Oriented Language
Procedural Languages • C, Pascal, FORTRAN, and similar languages are procedural languages. • each statement in the language tells the computer to do something: • A program in a procedural language is a list of instructions
Division into Functions • A procedural program is divided into functions, and (ideally, at least) each function has a clearly defined purpose and a clearly defined interface to the other functions in the program. • Dividing a program into functions and modules is one of the cornerstones of structured programming,
Problems with Structured Programming • Two problems: • First, functions have unrestricted access to global data. • Second, unrelated functions and data, the basis of the procedural paradigm, provide a poor model of the real world. • arrangement of separate data and functions does a poor job of modeling things in the real world
C and C++ • C++ is derived from the C language. • The most important elements added to C to create C++ are concerned with classes, objects, and Object-Oriented Programming.
Object oriented Programming • Complex real objects have both attributes and behaviour. Characteristics • People attributes ( eye color, job titles) • Car ( horse power and no. of doors). Behaviour • Behavior is like a function: you call a function to do something, like display the inventory, and it does it.
Object Oriented Programming In Oop we don’t deal with functions or procedural programming we deal with objects. The fundamental idea behind object-oriented programming is: • The real world consists of objects. Computer programs may contain computer world representations of the things (objects) that constitute the solutions of real world problems. Real world objects have two parts: -Properties (or state : characteristics that can change), - Behavior (or abilities : things they can do). • To solve a programming problem in an object-oriented language, the programmer no longer asks how the problem will be divided into functions, but how it will be divided into objects. The emphasis is on data
Why Object Technology • • • Flexibility Reusability Reduces time to adapt an existing system Reliability of the system increases Reducing the effort, cost, development, complexity and maintenance of software systems.
Characteristics of Object-Oriented Languages • • • Objects Classes Inheritance Reusability Data Abstraction Data encapsulation Creating new data types Information Hiding Polymorphism and Overloading
Characteristics of Object-Oriented Languages • Objects • In an object-oriented language, you no longer ask how the problem will be divided into functions, but how it will be divided into objects.
Data encapsulation. . Object Oriented Approach • The fundamental idea behind object-oriented languages is to combine into a single unit both data and the functions that operate on that data. Such a unit is called an object.
Object Oriented Programming • What kinds of things become objects in object-oriented programs? – Human entities: Employees, customers, salespeople, worker, manager – Graphics program: Point, line, square, circle, . . . – Mathematics: Complex numbers, matrix – Computer user environment: Windows, menus, buttons – Data-storage constructs: Customized arrays, stacks, linked lists
Classes • In OOP we say that objects are members of classes. • A class serves as a plan, or template. It specifies what data and what functions will be included in objects of that class. • A class is just a blue print, defining a class doesn’t create any object just as the mere existence of data type int doesn’t create any • variables.
Inheritance • The idea of classes leads to the idea of inheritance. • In our daily lives, we use the concept of classes as divided into subclasses. • We know that the class of animals is divided into mammals, amphibians, insects, birds, and so on. • The class of vehicles is divided into cars, trucks, buses, and motorcycles
Inheritance • each subclass shares common characteristics with the class from which it’s derived. Derived class use base class characteristics without modifying it and can add more features in derived class. • Cars, trucks, buses, and motorcycles all have wheels and a motor; these are the defining characteristics of vehicles. • In C++ the original class is called the base • class; other classes can be defined that share its characteristics, but add their own as well. These are called derived classes.
Reusability • Once a class has been written, created, and debugged, it can be distributed to other programmers for use in their own programs. • This is called reusability. It is similar to the way a library of functions in a procedural language can be incorporated into different programs. • in OOP, the concept of inheritance provides an important extension to the idea of reusability
Creating new data types • Problem with procedural language is that new data types can’t be created. We use same bulit in data type like float, double, interger. • In OOP, we can create our own data types.
Data Abstraction • Data Abstraction refers to providing only essential information to the outside work and hiding background details. • Data abstraction is a programming technique that relies on the separation of interface and implementation. • In C++, classes provided high level of abstraction. It has a lot of public methods which functions use … but don’t provide information about how the class is implemented.
Polymorphism and Overloading • Polymorphism is one thing with different forms …. . Like a function with different forms e. g a draw function can be used to draw circle, triangle, rectangle. • Overloading is the same having the same name of fucntion with different signatues( number and type of arguments or parameters used in any function. )
- Slides: 19