Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter-01 Programming Methodologies Procedural/Structured Design Objected-Oriented Design.

Similar presentations


Presentation on theme: "1 Chapter-01 Programming Methodologies Procedural/Structured Design Objected-Oriented Design."— Presentation transcript:

1 1 Chapter-01 Programming Methodologies Procedural/Structured Design Objected-Oriented Design

2 2 Object Autonomy? OOP

3 3 Algorithm (Unstructured Version) / * Algorithm to read and count several triples of distinct numbers and print the largest number in each triple. * / 1. Initialize count to 0 2. Read a triple x, y, z. 3. If x is the end-of-data flag then go to step 14. 4. Increment count by 1. 5. If x > y then go to step 9. 6. If y > z then go to step 12. 7. Display z. 8. Go to step 2. 9. If x < z then go to step 7. 10. Display x. 11. Go to step 2. 12. Display y. 13. Go to step 2. 14. Display count. Note the spaghetti logic!

4 4 Algorithm (Structured Version) / * Algorithm to read and count several triples of distinct numbers and print the largest number in each triple. * / 1. Initialize count to 0. 2. Read the first triple of numbers x, y, z. 3. While x is not the end-of-data-flag do the following: a. Increment count by 1. b. If x > y and x > z then display x. Else if y > x and y > z then display y Else display z. c. Read the next triple x, y, z. 4. Display count.

5 5 Different Programming: 1.Spaghetti code -with goto statements 2.Structured Programming -reduction of program into its constituent elements. 3.OOP -decomposes a problem into related subgroups Each subgroup becomes a self- contained object that contains its own instructions and data that relates to that object. Complexity is reduced and the programmer can manage large programs.

6 Bazlur Rasheed Functional Decomposition A technique for developing a program in which the problem is divided into more easily handled subproblems, the solutions of which create a solution to the overall problem. In functional decomposition, we work from the abstract (a list of the major steps in our solution) to the particular (algorithmic steps that can be translated directly into code in C++ or another language).

7 Bazlur Rasheed Functional Decomposition FOCUS is on actions and algorithms. BEGINS by breaking the solution into a series of major steps. This process continues until each subproblem cannot be divided further or has an obvious solution. UNITS are modules representing algorithms. A module is a collection of concrete and abstract steps that solves a subproblem. A module structure chart (hierarchical solution tree) is often created. DATA plays a secondary role in support of actions to be performed.

8 Bazlur Rasheed Compute Mileages Write Total Miles Module Structure Chart Main Get Data Round To Nearest Tenth Initialize Total Miles Open Files

9 Bazlur Rasheed Object-Oriented Design A technique for developing a program in which the solution is expressed in terms of objects -- self- contained entities composed of data and operations on that data. Private data << setf...... Private data >> get...... ignore cincout setw

10 Bazlur Rasheed More about OOD l languages supporting OOD include: C++, Java, Smalltalk, Eiffel, CLOS, and Object-Pascal l a class is a programmer-defined data type and objects are variables of that type l in C++, cin is an object of a data type (class) named istream, and cout is an object of a class ostream. Header files iostream and fstream contain definitions of stream classes l a class generally contains private data and public operations (called member functions)

11 Bazlur Rasheed Object-Oriented Design (OOD) FOCUS is on entities called objects and operations on those objects, all bundled together. BEGINS by identifying the major objects in the problem, and choosing appropriate operations on those objects. UNITS are objects. Programs are collections of objects that communicate with each other. DATA plays a leading role. Algorithms are used to implement operations on the objects and to enable interaction of objects with each other.

12 Bazlur Rasheed 12 Two Programming Methodologies Functional Object-Oriented Decomposition Design FUNCTION OBJECT Operations Data OBJECT Operations Data OBJECT Operations Data

13 Bazlur Rasheed 13 What is an object? OBJECT Operations Data set of functions internal state

14 Bazlur Rasheed 14 An object contains data and operations Private data: accoutNumber balance OpenAccount WriteCheck MakeDeposit IsOverdrawn GetBalance checkingAccount

15 Bazlur Rasheed Why use OOD with large software projects? l objects within a program often model real-life objects in the problem to be solved l many libraries of pre-written classes and objects are available as-is for re-use in various programs l the OOD concept of inheritance allows the customization of an existing class to meet particular needs without having to inspect and modify the source code for that class--this can reduce the time and effort needed to design, implement, and maintain large systems

16 Bazlur Rasheed Two Approaches to Building Manageable Modules Divides the problem into more easily handled subtasks, until the functional modules (subproblems) can be coded. Identifies various objects composed of data and operations, that can be used together to solve the problem. FUNCTIONAL DECOMPOSITION OBJECT-ORIENTED DESIGN FOCUS ON: processes FOCUS ON: data objects

17 17 A commercial for OOP: Two programming paradigms Procedural: ( C, FORTRAN, and Pascal ) –Action-oriented — concentrates on the verbs of a problem's specification –Programmers: Identify basic tasks to be performed to solve problem Implement the actions required to do these tasks as subprograms (procedures/functions/ subroutines) Group these subprograms into programs/modules/libraries, which together make up a complete system for solving the problem Object-oriented: ( C++, Java, and Smalltalk) –Focuses on the nouns of a problem's specification –Programmers: Determine what objects are needed for a problem and how they should work together to solve the problem. Create types called classes made up of data members and function members to operate on the data. Instances of a type (class) are called objects.


Download ppt "1 Chapter-01 Programming Methodologies Procedural/Structured Design Objected-Oriented Design."

Similar presentations


Ads by Google