Introduction to OOP with Java 4th Ed, C. Thomas Wu

Slides:



Advertisements
Similar presentations
Design by Contract.
Advertisements

Introduction To System Analysis and Design
1 SWE Introduction to Software Engineering Lecture 23 – Architectural Design (Chapter 13)
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Software Development Software Life Cycle UML Diagrams.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 1 CS 125 Introduction to Computers and Object- Oriented Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 1 Introduction to Object-Oriented Programming and.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 1 CS 125 Introduction to Computers and Object- Oriented Programming.
Object-oriented programming concepts An Introduction.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
Chapter Chapter 1 Introduction to Object-Oriented Programming and Software Development.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
Visual Basic Introduction IDS 306 from Shelly, Cashman & Repede Microsoft Visual Basic 5: Complete Concepts and Techniques.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Lecture 1 Introduction to Computers and Object-
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 1 Introduction to Object-Oriented Programming.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Software Engineering Software Development Process.
Sharif University of Technology Session # 7.  Contents  Systems Analysis and Design  Planning the approach  Asking questions and collecting data 
Unified Modeling Language
Introduction To System Analysis and design
Systems Analysis – Analyzing Requirements.  Analyzing requirement stage identifies user information needs and new systems requirements  IS dev team.
From Problem Statement to Design
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 1 Introduction to Object-Oriented Programming and.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 1: Introduction to Object-Oriented Programming.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
BCS 2143 Introduction to Object Oriented and Software Development.
1 A Student Guide to Object- Orientated Systems Chapter 4 Objects and Classes: the basic concepts.
OBJECT AND CLASES: THE BASIC CONCEPTS Pertemuan 8 Matakuliah: Konsep object-oriented Tahun: 2009.
1 CS 456 Software Engineering. 2 Contents 3 Chapter 1: Introduction.
SE-1010 Dr. Mark L. Hornick 1 Introduction to Object-Oriented Programming (OOP) Part 1.
Introduction to Java August 14, 2008 Mrs. C. Furman.
Introduction To System Analysis and Design
Object-oriented programming concepts An Introduction.
Systems Analysis & Design 7 th Edition Chapter 5.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class.
Programs and Classes A program is made up from classes Classes may be grouped into packages A class has two parts static parts exist independently Non-static.
© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Chapter 1 Introduction to Object-oriented Programming.
Object-Oriented Programming •Object-Oriented Programming (OOP) allows you to create your program based upon modeling objects.  Your program’s properties.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Getting Started with Java: Object declaration and creation Primitive.
Objective You will be able to define the basic concepts of object-oriented programming with emphasis on objects and classes by taking notes, seeing examples,
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 1 Introduction to Object-Oriented Programming and.
Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall Appendix A Object-Oriented Analysis and Design A.1.
CHAPTER 6 OBJECT ANALYSIS.
بسم الله الرحمن الرحيم CPCS203: Programming II. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display., Modifications by Dr.
Introduction to Computers and Programming Languages CS 180 Department of Computer Science Purdue University.
Visit for more Learning Resources
Intro to OOP with Java, C. Thomas Wu
Object-Oriented Analysis and Design
Object-Oriented Software Engineering Using UML, Patterns, and Java,
Mastering UML with Rational Rose 2002
Objectives State the reasons for the complexity involved in the development of software Define the following terms Objects Classes Messages Methods Explain.
About the Presentations
Introduction to Object-Oriented Programming
Object Oriented Concepts
Systems Analysis and Design With UML 2
Appendix A Object-Oriented Analysis and Design
Chapter 6-2 (Book Chapter 8)
Chapter 15 Recursive Algorithms Animated Version
Chapter 6-2 (Book Chapter 8)
Programs and Classes A program is made up from classes
Software Engineering System Modeling Chapter 5 (Part 1) Dr.Doaa Sami
Chapter 5.
Chapter 22 Object-Oriented Systems Analysis and Design and UML
DON’T PANIC!! Lots of new notions coming in these slides
Appendix A Object-Oriented Analysis and Design
Chapter 4 System Modeling.
Appendix A Object-Oriented Analysis and Design
Intro to OOP with Java, C. Thomas Wu
Presentation transcript:

Introduction to OOP with Java 4th Ed, C. Thomas Wu Chapter 1 Introduction to Object-Oriented Programming and Software Development ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. © The McGraw-Hill Companies, Inc.

Intro to OOP with Java, C. Thomas Wu Objectives After you have read and studied this chapter, you should be able to Name the basic components of object-oriented programming Differentiate classes and objects. Differentiate class and instance methods. Differentiate class and instance data values. Draw program diagrams using icons for classes and objects Describe significance of inheritance in object-oriented programs Name and explain the stages of the software lifecycle Upon completing this lesson and studying the corresponding sections from Chapter 1 of the textbook, you will have a basic understanding of classes, objects, methods, and data values. You should also be able to draw correct icons for classes and objects. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Intro to OOP with Java, C. Thomas Wu Classes and Objects Object-oriented programs use objects. An object is a thing, both tangible and intangible. Account, Vehicle, Employee, etc. To create an object inside the computer program, we must provide a definition for objects—how they behave and what kinds of information they maintain —called a class. An object is called an instance of a class. The two most important concepts in object-oriented programming are the class and the object. In the broadest term, an object is a thing, both tangible and intangible, which we can imagine. A program written in object-oriented style will consist of interacting objects. For a program to maintain bank accounts for a bank, for example, we may have many Account, Customer, Transaction, and ATM objects. An object is comprised of data and operations that manipulate these data. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Graphical Representation of a Class Intro to OOP with Java, C. Thomas Wu Graphical Representation of a Class We use a rectangle to represent a class with its name appearing inside the rectangle. <Class Name> Example: Account Motorcycle This is how we represent a class. The name of a class appears inside the rectangle. The example shows two classes: Account and Motorcycle. The notation we used here is based on the industry standard notation called UML, which stands for Unified Modeling Language. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Graphical Representation of an Object Intro to OOP with Java, C. Thomas Wu Graphical Representation of an Object We use a rectangle to represent an object and place the underlined name of the object inside the rectangle. <Object Name> Example: SV198 This is an object named SV198. This is how we represent an object. The name of an object also appears inside the rectangle, but unlike the class name, an object name is underlined. This example shows an object whose name is SV198. Notice that just by looking at this icon, we cannot tell what type of an object it is? Is it a Motorcycle? Or is an Account? We will use another notation, shown in the next slide, when we wish to identify the class it belongs to. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

An Object with the Class Name Intro to OOP with Java, C. Thomas Wu An Object with the Class Name This notation indicates the class which the object is an instance. <Object Name> : <Class Name> Example: SV198 : BankAccount This tells an object SV198 is an instance of the BankAccount class. To indicate the class of an object, we suffix the object name with a colon and the class name. The example shows an object SV198 is a BankAccount object. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Intro to OOP with Java, C. Thomas Wu Messages and Methods To instruct a class or an object to perform a task, we send a message to it. You can send a message only to the classes and objects that understand the message you sent to them. A class or an object must possess a matching method to be able to handle the received message. A method defined for a class is called a class method, and a method defined for an object is called an instance method. A value we pass to an object when sending a message is called an argument of the message. An object is not a passive container of information. Rather, it is an active entity capable of carrying out tasks. Tasks such as deducting a withdrawal amount from an account, computing the shortest route from your dorm to a classroom, and so forth. To command an object (or a class) to do something, we send a message to it. Not all objects (and classes) can respond to any messages sent them. They must be programmed to recognize messages. In other words, we define methods. Once a method is defined, then we can send a matching message. For example, we define a method, say, move to a MobileRobot object. Once this method is programmed correctly, then we can send a message to a MobileRobot object to move. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Intro to OOP with Java, C. Thomas Wu Sending a Message Message deposit with the argument 250.00 is sent to a BankAccount object SV198. deposit 250.00 SV198 : BankAccount Here’s an example of sending a message. This slide shows a sending of the message deposit to SV198. The BankAccount class must include a method named deposit. Otherwise, there will be an error because SV198 won’t be able to recognize the message. The name of the message we send to an object or a class must be the same as the method’s name. Because they are the same, the phrase “calling an object’s method” is synonymous to “sending a message to an object.” ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Sending a Message and Getting an Answer Intro to OOP with Java, C. Thomas Wu Sending a Message and Getting an Answer Ask for the current balance of this particular account. getCurrentBalance() SV198 : BankAccount current balance The deposit method in the previous slide is an action-only method. An object takes some action when called, but returns no answer back to the caller. The getCurrentBalance method in this slide is a value-returning method. When called, an object will return a value. The current balance of SV198 is returned. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Intro to OOP with Java, C. Thomas Wu Calling a Class Method Ask for the maximum possible speed for all MobileRobot objects is returned. MobileRobot getMaximumSpeed() maximum speed Here’s an example of calling a class method. It is not as common as the instance methods, but it can be handy in certain situations. The maximum speed of all MobileRobot objects is the same. Since the result is the same for all instances, we define getMaximumSpeed as a class method. General Idea: You define an instance method for a task that relates uniquely to individual instances (like getCurrentSpeed, which is different for individual mobile robots) and a class method for a task that relates to all instances of the class collectively. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Class and Instance Data Values Intro to OOP with Java, C. Thomas Wu Class and Instance Data Values An object is comprised of data values and methods. An instance data value is used to maintain information specific to individual instances. For example, each BankAccount object maintains its balance. A class data value is used to maintain information shared by all instances or aggregate information about the instances. For example, minimum balance is the information shared by all Account objects, whereas the average balance of all BankAccount objects is an aggregate information. Every object from the same class will have the same set of data values. The values themselves for individual objects would be different, of course. We assume here that the minimum balance is the same for all accounts. If this is the case, then the single value for minimum balance is shared by all Account objects. So we need to keep one value of the minimum balance that will be shared by all Account objects. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Sample Instance Data Value Intro to OOP with Java, C. Thomas Wu Sample Instance Data Value SV129 : BankAccount SV098 : BankAccount SV211 : BankAccount current balance 908.55 1304.98 354.00 Here we see that all instances of the BankAccount class has a data value named current balance. Although only one instance data value is shown here, it does not mean these objects contain only one data value. Most likely the real BankAccount objects would include about a dozen or so instance data values. We only show a single instance data value here so the diagram would not become cluttered. All three BankAccount objects possess the same instance data value current balance. The actual dollar amounts are, of course, different. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Sample Class Data Value Intro to OOP with Java, C. Thomas Wu Sample Class Data Value BankAccount minimum balance 100.00 There is one copy of minimum balance for the whole class and shared by all instances. SV098 : BankAccount SV211 : BankAccount SV129 : BankAccount current balance 908.55 1304.98 354.00 This line is an instance-of relationship. Here we see that a single class data value named minimum balance is shared by all instances. The dotted lines show the three objects are instance of the BankAccount class. To see the significance of a class data value, consider the situation where the minimum balance is represented as an instance data value. Because there’s only one value for the minimum balance, defining it as an instance data value would result in maintaining three copies of the same value, one copy per object. This is a waste of memory space. Not only that, more critically, keeping duplicates in memory will complicate the processing. When we have to change the value for the minimum balance, for example, we have to locate all copies and update them. Imagine updating the duplicates copies of 1000 BankAccount objects. This is a very time consuming and error-prone activity, which can be avoided easily by representing the information as a class data value. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Object Icon with Class Data Value Intro to OOP with Java, C. Thomas Wu Object Icon with Class Data Value SV129 : BankAccount current balance 908.55 minimum balance 100.00 When the class icon is not shown, we include the class data value in the object icon itself. When we do not include the class icon in a diagram, we can use this notation. Whether the data value name is underlined or not indicates the information is a class or an instance data value. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Intro to OOP with Java, C. Thomas Wu Inheritance Inheritance is a mechanism in OOP to design two or more entities that are different but share many common features. Features common to all classes are defined in the superclass. The classes that inherit common features from the superclass are called subclasses. We also call the superclass an ancestor and the subclass a descendant. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Intro to OOP with Java, C. Thomas Wu A Sample Inheritance Here are the superclass Account and its subclasses Savings and Checking. Account Checking Savings ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Inheritance Hierarchy Intro to OOP with Java, C. Thomas Wu Inheritance Hierarchy An example of inheritance hierarchy among different types of students. Student Graduate Undergrad Commuting Resident Law Masters Doctoral ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Intro to OOP with Java, C. Thomas Wu Software Engineering Much like building a skyscraper, we need a disciplined approach in developing complex software applications. Software engineering is the application of a systematic and disciplined approach to the development, testing, and maintenance of a program. In this class, we will learn how to apply sound software engineering principles when we develop sample programs. When a construction firm builds a house, it will follow a strict construction sequence that is based on sound engineering principles. Although software is not a physical object, it is just as complex as a building. And we also need to follow a strict software construction sequence if we expect to build an error-free software. We need a software construction sequence that is based on sound software engineering principles. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.

Intro to OOP with Java, C. Thomas Wu Software Life Cycle The sequence of stages from conception to operation of a program is called software life cycle. Five stages are Analysis Design Coding Testing Operation and Maintenance In the analysis phase, we perform a feasibility study. We analyze the problem and determine whether a solution is possible. If a solution is possible, the result of this phase is a requirements specification which describes the features of a program. In the design phase, we turn a requirements specification into a detailed design of the program. For an object-oriented design, the output from this phase will be a set of classes/objects that fulfill the requirements. In the coding phase, we implement the design into an actual program, in our case, a Java program. In the testing phase, we run the program using different sets of data to verify that the program runs according to the specification. Two types of testing are possible for object-oriented programs: unit testing and integration testing. With unit testing, we test classes individually. With integration testing, we test that the classes work together correctly. Activity to eliminate programming error is called debugging. An error could be a result of faulty implementation or design. When there's an error, we need to backtrack to earlier phases to eliminate the error. Finally, after the testing is successfully concluded, we enter the operation phase in which the program will be put into actual use. The most important and time-consuming activity during the operation phase is software maintenance. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ©The McGraw-Hill Companies, Inc.