Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Object-Oriented Programming Using C++ CLASS 17 Honors.

Similar presentations


Presentation on theme: "1 Object-Oriented Programming Using C++ CLASS 17 Honors."— Presentation transcript:

1 1 Object-Oriented Programming Using C++ CLASS 17 Honors

2 2 Understand the difference between Structured Programming and Object-Oriented Programming Objectives

3 3 What is Object-Oriented Programming? A new way of thinking A different approach to the solution to a problem

4 4 Object-Oriented Design vs. Structured Approach Decompose the problem into tasks Write procedures (functions) to solve simple tasks and compose them into a more sophisticated process until desired functionality is reached Structured Approach

5 5 Object-Oriented Design vs. Structured Approach Little regulation of access to data Focus is on looking for operations Unit testing/integration Structured Approach

6 6 Object-Oriented Design vs. Structured Approach Describe a problem in terms of things rather than activities Object-Oriented Approach

7 7 What action does an elevator perform? Goes up Goes down What does an elevator contain? • Button • Rider

8 8 Object-Oriented Design vs. Structured Approach Identify objects and the operations to be performed on these objects Object-Oriented Approach

9 9 What does a rider do with an elevator? Gets on Gets off Pushes buttons

10 10 Object-Oriented Design vs. Structured Approach Object-oriented design and programming encourages gradual growth by attaching more working class clusters and repeated testing Object-Oriented Approach

11 11 What are Some Problems with the Structured Approach Time estimates Low-quality High-maintenance Duplication of effort What is the Solution • Improve the tool (the language) • Improve the process

12 12 Word Processing Program In a structured approach... 2000 functions A program bug is detected Problem could be in any of those functions

13 13 Word Processing Program In OOP, every operation is associated with a particular class. Error detection is quicker: We could have 100 classes with 20 operations per class. A program bug is detected Problem is in one of the 100 classes

14 14 A simple OOD example showing ease of extension/modification to software: You are given an assignment to write a program to create and print out a database of inventory items.

15 15 Inventory Getdata for item Printdata for item

16 16 Inventory Getdata for item Printdata for item Getdata Prompt and read in item # Prompt and read in unit price Prompt and read in quantity in stock

17 17 Inventory Getdata for item Printdata for item Getdata Prompt and read in item # Prompt and read in unit price Prompt and read in quantity in stock Printdata Print item # Print item price Print item quantity

18 18 Pipes Need length, size and type Light Bulbs Paint Watts Size Color

19 19 Create a pipe object Inventory - Object-Oriented Approach

20 20 Create a pipe object Apply getdata to pipe object Inventory - Object-Oriented Approach

21 21 Create a pipe object Apply getdata to pipe object Pipe object has it’s own getdata also Inventory - Object-Oriented Approach

22 22 Create a pipe object Apply getdata to pipe object Pipe object has it’s own getdata also Create a light bulb object Inventory - Object-Oriented Approach

23 23 Create a pipe object Apply getdata to pipe object Pipe object has it’s own getdata also Create a light bulb object Apply getdata to light bulb object Inventory - Object-Oriented Approach

24 24 Create a pipe object Apply getdata to pipe object Pipe object has it’s own getdata also Create a light bulb object Apply getdata to light bulb object Light object has it’s own getdata also Inventory - Object-Oriented Approach

25 25 Create a pipe object Apply getdata to pipe object Pipe object has it’s own getdata also Create a light bulb object Apply getdata to light bulb object Light object has it’s own getdata also Create a paint object Inventory - Object-Oriented Approach

26 26 Create a pipe object Apply getdata to pipe object Pipe object has it’s own getdata also Create a light bulb object Apply getdata to light bulb object Light object has it’s own getdata also Create a paint object Apply getdata to a paint object Inventory - Object-Oriented Approach

27 27 Apply printdata to the above objects Inventory - Object-Oriented Approach

28 28 13.1 Procedural and Object- Oriented Programming Procedural programming is a method of writing software. It is a programming practice centered on the procedures, or actions that take place in a program. Object-Oriented programming is centered around the object. Objects are created form abstract data types that encapsulate data and functions together.

29 29 What’s Wrong with Procedural Programming? Programs with excessive global data Complex and convoluted programs Programs that are difficult to modify and extend

30 30 What is Object-Oriented Programming? OOP is centered around the object, which packages together both the data and the functions that operate on the data.

31 31 Figure 13-1

32 32 Terminology In OOP, an object’s member variables are often called its attributes and its member functions are sometimes referred to as its behaviors or methods.

33 33 Figure 13-2

34 34 13.2 How are Objects Used? Although the use of objects is only limited by the programmer’s imagination, they are commonly used to create data types that are either very specific or very general in purpose.

35 35 General Purpose Objects Creating data types that are improvements on C++’s built-in data types. For example, an array object could be created that works like a regular array, but additionally provides bounds-checking. Creating data types that are missing from C++. For instance, an object could be designed to process currencies or dates as if they were built-in data types. Creating objects that perform commonly needed tasks, such as input validation and screen output in a graphical user interface.

36 36 Application-Specific Objects Data types created for a specific application. For example, in an inventory program.

37 37 Advantages of Object-Oriented Programming Data abstraction details of classes only visible to its methods Compatibility easier to combine software components Flexibility classes provide units for task allocation

38 38 Advantages of Object-Oriented Programming Reuse easier to develop reusable software Extensibility inheritance allows new classes to be built from old ones Maintenance The natural modularity of the class structures makes it easier to contain the effects of change

39 39 Q & A


Download ppt "1 Object-Oriented Programming Using C++ CLASS 17 Honors."

Similar presentations


Ads by Google