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.
Chapter 1 Object-Oriented System Development
Object Oriented System Development with VB .NET
Basic OOP Concepts and Terms
Systems Analysis & Design Sixth Edition Systems Analysis & Design Sixth Edition Toolkit Part 5.
Chapter 13: Object-Oriented Programming
C++ fundamentals.
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.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Developing a Program.
Object Orientation An Object oriented approach views systems and programs as a collection of interacting objects. An object is a thing in a computer system.
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.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 8: More About OOP and GUIs.
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.
Systems Analysis & Design 7 th Edition Chapter 5.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
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.
 By the end of this lecture, you should …  Understand the three pillars of Object- Oriented Programming: Inheritance, Encapsulation and Polymorphism.
Chapter 11: Abstract Data Types Lecture # 17. Chapter 11 Topics The Concept of Abstraction Advantages of Abstract Data Types Design Issues for Abstract.
Programming Logic and Design Seventh Edition Chapter 12 Event-Driven GUI Programming, Multithreading, and Animation.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Principles of Programming & Software Engineering
Visual Basic.NET Windows Programming
OOP - Object Oriented Programming
Object-Orientated Programming
Visit for more Learning Resources
Object Oriented Programming
The Movement To Objects
Introduction to Programming and Visual Basic
Object-Oriented Analysis and Design
Chapter Topics 15.1 Graphical User Interfaces
Introduction to Visual Basic 2008 Programming
Object-Oriented Techniques
An Introduction to Computers and Visual Basic
Chapter 11 Object-Oriented Design
Unified Modeling Language
An Introduction to Computers and Visual Basic
Object Oriented Concepts
An Introduction to Visual Basic
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
VISUAL BASIC.
Inheritance Basics Programming with Inheritance
Chapter 10 Thinking in Objects
Object-oriented design for multiple classes
Computer Programming with JAVA
An Introduction to Computers and Visual Basic
Chapter 15: GUI Applications & Event-Driven Programming
Basic OOP Concepts and Terms
Chapter 5.
Presentation transcript:

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

8.1 Classes 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

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

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 Function GetVolume() As Real Set GetVolume = Volume End Function Function GetSide() As Real Set GetSide = Side End Class

Classes and Objects (continued) 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

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.

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.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.

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

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.

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.

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.

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.

Developing an OOP Program The analysis phase of developing an OOP program entails: Identifying the classes to be used in the program Determining the attributes needed for the classes Determining the methods needed for the classes 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.

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

8.3 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.

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.

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

7.3 Functions Example GUI

8.4 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.

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.

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.)

Pseudocode Language (Ch 8) In this chapter we added some more syntax to our language. We discussed how create classes and objects. 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