Вы находитесь на странице: 1из 47

An object oriented language is used when there is a need for re-usability of the definedobject or set of objects that are

common within a program or between many applications

An approach that provides a way of modularizing programs by creating partitioned memory area for both data and functions that can be used as templates for creating copies of such modules on demand

Emphasis

is on data rather than

procedure Programs are divided into objects Data structures are designed such that they characterize objects Functions that operate on the data of an object are tied together in the data structure

Data

is hidden and cannot accessed by external functions Objects may communicate with each other through functions New data and functions can be easily added whenever necessary Follows Bottom-up approach in program design

customers are allowed to have different types of bank accounts, deposit money, withdraw money and transfer money between accounts

Focus

is on procedures All data is shared: no protection More difficult to modify Hard to manage complexity

Procedural

Object Oriented

Withdraw, deposit, transfer

Customer, money, account

Objects in the problem domain are mapped to objects in software

011101 10011

0110100 010101 11101

1110101 11010 10101

Data and operations are grouped together

Account
Withdraw Deposit Transfer

Interface: Set of available operations

Objects Classes Data

abstraction and encapsulation Inheritance Polymorphism Dynamic binding Message passing

Objects: Objects are the basic run-time entities in an object-oriented system. Programming problem is analysed in terms of objects and the nature of communication between them. Objects take up space in the memory and have an associated address like a record in pascal or a structure in C.

An object can be characterised by the following : 1.An identity 2.A state 3.A behavior

Classes: The entire set of data and code of an object can be made user-defined data type with the help of a class. Objects are variables of the type class. A class is a collection of objects of similar type. Classes are user-defined data types and behave like the build-in type of a programming language.

Classes reflect concepts, objects reflect instances that embody those concepts. object girl class

Jodie

Daria

Jane

Brittany

Class
Visible in source code The code is not duplicated

Object
Own copy of data Active in running program Occupies memory Has the set of operations given in the class

Data abstraction and encapsulation: The wrapping up of data and functions into a single unit is known as encapsulation. It is the most striking feature of a class. The insulation of the data from direct access by the program is called data hiding or information hiding. Abstraction refers to the act of representing essential features

class Account { public: float withdraw(); void deposit(float amount); private: float balance; );

Protection Consistency Allows change

Inheritance:

The process by which objects of one class acquire the properties of objects of another class. It supports the concept of hierarchial classification. In OOP, the concept of inheritance provides the idea of reusability we can add additional features to an existing class without modifying it.

Polymorphism: Means the ability to take more than one form. 2 types of overloading. The process of making an operator to exhibit different behaviours in different instances is known as operator overloading. If a single function is used to perform different type of tasks then it is function overloading.

Dynamic binding: Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run-time. Message passing: Objects communicate with one another by sending and receiving information .

Programming advantages: A class binds all the member functions together for creating objects.eg:Psoftware timer gets count input from a real time clock is an object-sothat a number of software timer objects can be created as instances of RTCSWT.

Class can derive (inherit) from another class.eg:creating a child class from RTCSWT as a parent class create a new application of RTCSWT. Methods can have same name in the inherited class-method overloading. Methods can have the same name as well as the same number and type of arguments in the inherited classmethod overriding.

Operators

in C++ can be overloaded like in method overloading. #include<iostream.h> Class space { intx,y,z; public: void getdata(int a,int b,int c); void display(void); void operator~(); //overloaded unary minus };

Void space::getdata(int a,int b,int c) int main() { { X=a; space s; Y=b; s.getdata(10,20,30); Z=c; cout<<s: ; } s.display(); Void space::display(void) -s; { cout<<s: ; Cout<<x<< ; s.display(); Cout<<y<< ; return 0; Cout<<z<<\n; } } Void space::operator~() OUTPUT: { S:10 -20 30 X=-x; S:-10 20 -30 Y=-y; Z=-z;

Class A { int x; Public: Void show( ){..} }; Class B:public A { int y; Public: Void show( ){} };

//base class

//derived class

Program codes become lengthy,when certain features of c++ are used. Features are Template Multiple inheritance Exceptional handling Virtual base classes

Deriving a class from more than one direct base class is called multiple inheritance. In the following example, classes A, B, and C are direct base classes for the derived class X: class A { /* ... */ }; class B { /* ... */ }; class C { /* ... */ }; class X : public A, private B, public C { /* ... */ };

Exception handling is a mechanism that separates code that detects and handles exceptional circumstances from the rest of your program. When a function detects an exceptional situation, you represent this with an object. This object is called an exception object. In order to deal with the exceptional situation you throw the exception.

Embedded codes can be optimised when using OOP by following: Declare private as many classes as possible Use char, int and boolean in place of objects as arguments Recover memory already used once by changing the reference to an object to NULL

Embedded C ++ compilers make the C++ significantly more powerful coding language than C for embedded systems. GNU C/C++ compilers-extensive use in C++ environment in embedded software development. Other compiler-Diab compiler from Diab data-provides .target specific optimisation

Compiler

for the host computer which does the development and design,testing,debugging. Cross compiler-runs on host but develops machine codes for a targeted system.

GNU

compiler is configurable both as host compiler as well as cross compiler. It supports 80X86,windows 95/NT,80x86 Red Hat Linux,68HC11,power PC. A compiler creates object file. Host compiler can be turbo C,turbo C++ or Boland C and Borland C++. Cross compiler supports PIC family,80196 family,PIC 16F84 or

Host

also runs the cross compiler that offers an integrated development environment. A target system can emulate and simulate. An emulator in computing duplicates (provides an emulation of) the functions of one system using a different system, so that the second system behaves like (and appears to be) the first system..

This

focus on exact reproduction of external behavior is in contrast to some other forms of computer simulation, which can concern an abstract model of the system being simulated. Eg:computer specially built for running programs designed for another architecture is an emulator. In contrast, a simulator could be a program which runs on a PC, so that

Вам также может понравиться