0% found this document useful (0 votes)
2 views

basics of oops

Basic of oops

Uploaded by

Dj Freefire
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
2 views

basics of oops

Basic of oops

Uploaded by

Dj Freefire
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 8
4 @—________. Object-Oriented Programming with C++ These include techniques such as modular programming, top-down pregraniming, bottom: up programming and structured programming. The primary motivation in each has been the concern to handle the inereasing complexity of programs that are reliable and maintainable. These techniques have become popular among programimers over the last two decades. Objectoriented programming eo Layers of Computer software With the advent of languages such as C, structured programniing became very popular and was the main technique of the 1980s. Structured programming was a powerful tool that enabled programmers to write moderately complex programs fairly easily. However, as the programs grew larger, even the structured approach failed to show the desired results in terms of bug-free, easy-to-maintain, and reusable programs. Object-Oriented Programming (OOP) is an approach ta program organization and development that attempts to eliminate some of the pitfalls of conventional programming methods by ‘incorporating the best of structured programming features with several powerful new concepts. It is a new way of organizing and developing programs and has nothing to do with any particular language. However, not all languages are suitable to implement the OOP concepts easily, I 3 A Look at Procedure-Oriented Programming Conventional programming, using high level languages such as COBOL, FORTRAN and ©, is commonly known as procedure-oriented programming (POP). In the procedure-oriented approach, the problem is viewed as a sequence of things to be done such as reading, calculating, Prinuples of Object-Oriented Programming ——————® 5 and printing. A number of functions are written to accomplish these tasks. The primary focus is on functions, A typical program structure for procedural programming is shown in Fig, 1.4. ae oe ye ae oe et tere eke he for solving a problem. ‘Procedure-oriented. programming basically consists of writing a list of instructions (or actions) for the computer to follow, and organizing these instructions into groups known as functions. We normally use a flowchart to organize these actions and represent the flow of control from ene action to another. While we concentrate on the development of functions, very little attention is given to the data that are being used by various functions. What happens to the data? How are they affected by the functions that work on them? Ina multi-function program, many important data items are placed as global so that they may be accessed by all the functions, Each function may have its own locat data, Figure 1.5 shows the relationship of data and functions in a procedure-oriented program. Global data are more vulnerable to an inadvertent change by a function, In a large program it is very difficult to identify what data is used by which function. In case we need to revise an external data structure, we also need to revise all functions that access the data, This provides an opportunity for bugs ta creep in, Another serious drawback with the procedural approach is that it does not model real world problems very well. This is because functions are action-oriented and do not really correspond to the elements of the problem. 6 6. ject-Orientedt Programming smith C++ Some characteristics exhibited by procedure-oriented programming are: Emphasis is on doing things (algorithms). Large programs are divided into smaller programs known as functions. Most of the functions share global data. Data move openly around the system from function to function. Funetions transform data from one form to another. Employs top-down approach in program design, l 4 Object-Oriented Programming Paradigm ‘The major motivating factor in the invention of object-oriented approach is to remove some of the flaws encountered in the procedural approach. OOP treats data as a critical element in the program development and does not allow it to flow freely around the system. It ties data more closely to the functions that operate on it, and protects it from accidental modification from outside functions, OOP allows decomposition of a problem into a number of entities called objects and then builds data and functions around these objects. The organization of data and functions in object-oriented programs is shown in Fig. 1.6. The data of an object can be accessed only by the functions associated with that object. However, functions of one object ean access the functions of other objects. ‘Some of the striking features of object-oriented programming are: @ Emphasis js on data rather than procedure. Programs are divided into what are known as objects. © Data structures are designed such that they characterize the objects. Principles of Object-Oriented Programming ——————@ 7 ® Functions that operate on the data of an object are tied together in the data strue- ture. © Data is hidden and cannot be necessed hy 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, Object A Object 8 Object-oriented programming is the most recent concept among programming paradigms and still means different things to different people. ripper tial py definition of object-oriented programming before we proceed further. We define “object- oriented programming as 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.” Thus, an object ia considered to be a partitioned area of computer memory that stores data and set of operations that can access that data. Since the memory partitions are independent, the objects can be used in a variety of different programs without modifications, bs Basic Concepts of Object-Oriented Programming It is necessary to understand some of the concepts used extensively in object-oriented programming. These include: © Objects ® Classes 12 @—__________. Otject- Oriented Programming with C++ A message for an object is a request for execution of a procedure, and therefore will invoke a function (procedure) in the receiving object that generates the desired result. Message passing involves specifying the name of the object, the name of the function (message) and the tion to be sent. Example: ‘employes salary (name); 4 4 object Information message Objects have a life eyele. They can be created and destrayed. Communication with an object is feasible as long-as it is alive, OOP offers several benefits to both the program designer and the user. Object-orientation contributes to the solution of many problems associated with the development and quality of software products, The new technology promises greater programmer productivity, better quality of software and lesser maintenance cost. The principal advantages are: \& Through inheritance, we ean eliminate redundant code and extond the use of exist- yy Weean build programs from the standard working modules that communicate with one another, rather than having to start writing the code from scratch. This leads to saving of development time and higher productivity. \L® The principle of data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the program.

You might also like