Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 8: More About OOP and GUIs.

Slides:



Advertisements
Similar presentations
An Introduction to Visual Basic Terms & Concepts.
Advertisements

OOP - Object Oriented Programming Object Oriented Programming is an approach to programming that was developed to make large programs easier to manage.
Systems Analysis and Design 8th Edition
Chapter 1 Object-Oriented System Development
Automating Tasks With Macros
1 :)Advanced:) Visual Basic laura leventhal and julie barnes.
Object Oriented System Development with VB .NET
Basic OOP Concepts and Terms
Java Programming, 3e Concepts and Techniques Chapter 1 An Introduction to Java and Program Design.
Systems Analysis & Design Sixth Edition Systems Analysis & Design Sixth Edition Toolkit Part 5.
Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved.
Chapter 13: Object-Oriented Programming
Chapter 1 Program Design
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
C++ fundamentals.
A Tour of Visual Basic BACS 287. Early History of Basic Beginners All-Purpose Symbolic Instruction Code An “Interpreted” teaching language English-like.
CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Object-Oriented Programming (OOP)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Java Programming, 2E Introductory Concepts and Techniques Chapter 1 An Introduction to Java and Program Design.
A First Program Using C#
Visual Basic Chapter 1 Mr. Wangler.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Developing a Program.
Introduction to Object-oriented programming and software development Lecture 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
An Object-Oriented Approach to Programming Logic and Design
COMPUTER PROGRAMMING Source: Computing Concepts (the I-series) by Haag, Cummings, and Rhea, McGraw-Hill/Irwin, 2002.
An Introduction to Visual Basic
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
CHAPTER ONE Problem Solving and the Object- Oriented Paradigm.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
1 Systems Analysis and Design in a Changing World, Thursday, January 18, 2007.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Systems Analysis & Design 7 th Edition Chapter 5.
Systems Analysis and Design 8 th Edition Chapter 6 Object Modeling.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
Basic OOP Concepts and Terms. In this class, we will cover: Objects and examples of different object types Classes and how they relate to objects Object.
Module 4 Part 2 Introduction To Software Development : Programming & Languages Introduction To Software Development : Programming & Languages.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Learners Support Publications Object Oriented Programming.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 12 Object-Oriented Programming Starting Out with Games & Graphics.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Chapter 5 System Modeling. What is System modeling? System modeling is the process of developing abstract models of a system, with each model presenting.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 14 Event-Driven Programming with Graphical User Interfaces.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
 By the end of this lecture, you should …  Understand the three pillars of Object- Oriented Programming: Inheritance, Encapsulation and Polymorphism.
Programming Logic and Design Seventh Edition Chapter 12 Event-Driven GUI Programming, Multithreading, and Animation.
OOP - Object Oriented Programming
Object-Orientated Programming
The Movement To Objects
Chapter 8: More About OOP and GUIs
Object-Oriented Analysis and Design
Chapter Topics 15.1 Graphical User Interfaces
An Introduction to Computers and Visual Basic
An Introduction to Visual Basic
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
VISUAL BASIC.
An Introduction to Computers and Visual Basic
Chapter 15: GUI Applications & Event-Driven Programming
Basic OOP Concepts and Terms
Presentation transcript:

Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 8: More About OOP and GUIs

2 8.1Classes and Objects A class is a data type that allows us to create objects. It provides the definition for a collection of objects by describing its attributes (data) and methods (operations) that may be applied to that data. For example, consider the following definition of the class television: Its attributes include brand name, model number, dimensions, screen size, and so on Its methods include turning it on and off, changing the volume, changing channels, and so on

3 Classes and Objects (continued) An object is an instance of a class. With one class, you can have as many objects as required. This is analogous to a variable and a data type. The class is the data type and the object is the variable. Declare Number As Integer Declare ObjectName As ClassName

4 Classes and Objects (continued) Class Cube Side As Real Volume As Real Subprogram SetSide(NewSide) Set Side = NewSide End Subprogram Subprogram ComputeVolume() Set Volume = Side ^ 3 End Subprogram Function GetVolume() As Real Set GetVolume = Volume End Function Function GetSide() As Real Set GetSide = Side End Function End Class

5 Here is an example of some code that makes an object of type Cube, and calls the functions that are part of the object. Main Program Declare Cube1 As Cube Write “Enter a positive number:” Input Side1 Call Cube1.SetSide(Side1) Call Cube1.ComputeVolume Write “Volume of a cube of side”, Cube1.GetSide Write “is ”, Cube1.GetVolume End Program Classes and Objects (continued)

6 The Constructor A constructor is like a model or plan to construct an object. In programming, it is a special method, included in the class definition, which performs setup tasks when an object is created. The constructor initializes the objects attributes and establishes conditions that do not change in the class.

7 The Constructor (continued) In the Cube example, a constructor might have given initial values to the two attributes – Side and Volume – of 1 and 1, respectively. Then, when the main program calls the function ComputeVolume before the Side attribute is given a value, a value of 1 is already there, ready to be replaced by whatever value is necessary, and there will not be a problem.

8 8.2 More About Object-Oriented Programming Procedural programming and object-oriented programming are not mutually exclusive. The emphasis in procedural programming is to define the modules that represent processes and to attach these processes together to create a complex system. In OOP the emphasis is on the definition of the objects that are needed to solve a problem and how those objects interact with each other.

9 Object-Oriented Programming (continued) Benefits of object-oriented languages –OOP is better equipped to deal with extremely complex software than procedural languages OOP uses inheritance, encapsulation, and polymorphism (to be discussed) –OOP became the natural way to program GUI interfaces

10 Object-oriented Programming (continued) Encapsulation — The incorporation of data and operations on that data into a single unit in such a way that the data can only be accessed through these operations. This is the fundamental idea behind classes and objects. Inheritance — The ability to create new classes that are based on existing ones. The methods (operations) and attributes (data) of the original class are usually incorporated into the new class, together with methods and attributes specific to the latter. Polymorphism — The ability to create methods that perform a general function, which automatically adapts itself to work with objects of different classes.

11 Inheritance In the previous example of Class Cube, we saw that a Cube has a Volume. The ‘has a’ relationship identifies the properties of the class. There is also an ‘is a’ relationship that defines inheritance. For example a Truck is a Vehicle. If we have defined a Class Vehicle, and included all of the properties that all Vehicles have, then it is very efficient to define new classes as specialized versions of existing classes. We say that the Class Truck inherits the properties of the Class Vehicle.

12 Polymorphism Polymorphism allows a method to take on many definitions when applied to objects in a hierarchy of classes. If a method or attribute that is already defined in the parent class is then redefined in the child class, the class closest to the calling instance takes precedence.

13 Polymorphism In an imaginary parent (base) class called Vehicle, we might have methods to compute the Speed, given MilesTraveled and Time and to compute GasMileage given GasUsed and MilesTraveled. A child (derived) class called DeiselCar might use the Speed method from the parent class but use its own method for GasUsed since the formula for a deisel engine might differ from that of other engines.

14 Developing an OOP Program The analysis phase of developing an OOP program entails: 1.Identifying the classes to be used in the program 2.Determining the attributes needed for the classes 3.Determining the methods needed for the classes 4.Determining the relationships among the classes In real-life programs there may hundreds or thousands of methods. Encapsulating them in objects makes it easier to manage them.

15 Modeling Languages An object modeling language is a standardized set of symbols used to model parts of an object-oriented software design Unified Modeling Language (UML) is one of the primary languages –non-proprietary, general purpose –used to create an abstract model of a system

Graphical User Interface Revisited Object-oriented programming is used heavily for the development of GUI applications. Each of the GUI components, such as a button, a check box, a text box, etc. is a class Each instance of a button, check box, a text box, etc. is an object of that class. Some languages have GUI development as a central part of the language. – Visual Basic in particular is most well known for the rapid creation of GUIs for Windows platforms.

17 GUIs Although there is some variation among the languages and operating systems, the components that make up a GUI application are fairly standard, and the way to interact with them is also fairly standard. For example, if there is a text box, the user will click once to put the cursor in the text box, and then type some information into that box.

18 Window Components Command buttons Check boxes Labels Option buttons Drop-down list boxes List boxes Text boxes

Functions Example GUI

Event-driven Programming The use of a GUI is based on the user’s interaction with the interface – clicking buttons, pulling down menus, etc. Each of these user actions generates an event. Event-driven programming is not separate from procedural, nor from GUI programming, but the emphasis is on changing the flow of control in the program based on the events generated by the user.

21 Event-driven Programming (continued) In event-driven programming there is no main program. When an event driven program is executed, it presents a GUI and waits for the user to generate an event to determine which code is executed next. It is up to the designer of the program to create a GUI that only allows the user to generate events that make sense at any given time in the execution of the program.

22 Event-driven Program Design The analysis phase of an event-driven program design is similar to that of an object-oriented program. Here are the basic steps involved: 1. Identify the windows needed in the program. 2. Determine the relationships among the windows; for example, which window can open another (so that the latter appears on the screen). Such relationships can be pictured in a flow diagram 3.For each window: Determine the components (command buttons, text boxes, etc.) needed for that window. Draw a rough sketch of the resulting window. Determine the properties and methods needed for the window and each of its components. (The methods need not be ‘fleshed out” in this phase.)

23 Pseudocode Language (Ch 8) Defining A Class Class ClassOne Variable1 As Type Variable2 As Type Subprogram Method1(parameter) … End Subprogram Function Method2() As Type … End Function End Class Define and use an object Main Declare Obj1 As ClassOne … Call Obj1.Method1(params) Call Obj1.Method2 … End Program In this chapter we added some more syntax to our language. We discussed how create classes and objects.