© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter 1 - 1 Chapter 1 Introduction to Object-oriented Programming.

Slides:



Advertisements
Similar presentations
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Getting Started with Java.
Advertisements

Introduction to Object Orientation System Analysis and Design
DONT PANIC!! Lots of new notions coming in these slides Dont worry if not all of it makes perfect sense Well meet most of this stuff again in detail later.
Inheritance In object-oriented programming, a mechanism called inheritance is used to design two or more entities that are different but share many common.
Intro to OOP with Java, C. Thomas Wu Inheritance and Polymorphism
cMichael Fung, CS&E, The Chinese University of HK1 Object-Oriented Programming Using Java Introduction to OOP.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
©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.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
©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 Lecture 1 Introduction to Computers and Object-
Chapter 10 Classes Continued
Polymorphism. Lecture Objectives To understand the concept of polymorphism To understand the concept of static or early binding To understand the concept.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
©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.
Inheritance and Subclasses in Java CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University.
TCU CoSc Introduction to Programming (with Java) Getting to Know Java.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
©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.
BCS 2143 Introduction to Object Oriented and Software Development.
Chapter 8 More Object Concepts
An Object-Oriented Approach to Programming Logic and Design
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
SE-1010 Dr. Mark L. Hornick 1 Introduction to Object-Oriented Programming (OOP) Part 1.
Object-oriented programming concepts An Introduction.
Objective You will be able to define and identify the basic components of a java program by taking notes, seeing examples, and completing a lab. Construction.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Parameters… Classes Cont Mrs. C. Furman October 13, 2008.
©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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
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.
SE-1010 Dr. Mark L. Hornick 1 Java Programming Basics.
Object-Oriented Programming •Object-Oriented Programming (OOP) allows you to create your program based upon modeling objects.  Your program’s properties.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Getting Started with Java: Object declaration and creation Primitive.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Topics Inheritance introduction
Inheritance and Subclasses CS 21a. 6/28/2004 Copyright 2004, by the authors of these slides, and Ateneo de Manila University. All rights reserved L16:
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,
AP Computer Science A – Healdsburg High School 1 Unit 2 - Object-Oriented Programming - Example.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 1 Introduction to Object-Oriented Programming and.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Chapter 4 : Defining Your Own Classes Part 1 - Objectives After you have read and studied this chapter, you should be able to Define a class with multiple.
بسم الله الرحمن الرحيم 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.
2-Oct-16 Basic Object-Oriented Concepts. 2 Concept: An object has behaviors In old style programming, you had: data, which was completely passive functions,
Inheritance ITI1121 Nour El Kadri.
Introduction to Object-Oriented Programming
Introduction to OOP with Java 4th Ed, C. Thomas Wu
Can perform actions and provide communication
Chapter 2 Java Programming Basics
Introduction to Object-Oriented Programming with Java--Wu
Software Design Lecture : 12.
Programs and Classes A program is made up from classes
DON’T PANIC!! Lots of new notions coming in these slides
Getting Started with Java
Intro to OOP with Java, C. Thomas Wu
Presentation transcript:

© 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 and Software Development

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Chapter 1 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 object diagrams using icons for classes, objects, and other components of object-oriented programming. Describe the significance of inheritance in object- oriented programs.

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter 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.

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Graphical Representation of an Object Account SV129 The class name is placed inside the object icon. The object’s name appears on top of the icon. An icon for an object is the rounded rectangle. The class name may be omitted when it is clear from the context which class the object belongs to. customer1

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Graphical Representation of a Class Account The class name appears on top of the icon. An icon for a class is the rectangle.

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Instance-of Relationship Employee Bill Employee Steve Employee Andy The class name can be omitted since it is clear which class these objects belong to. The dotted line shows the instance-of relationship. Before you can create instances of a class, the class must be defined.

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter 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.

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Sending a Message Message deposit with the argument is sent to chk-008. Account chk-008 deposit deposit Message name is usually omitted in the diagram. deposit

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Sending a Message and Getting an Answer This message has no argument. Account chk-008 getMonthlyFee monthly fee The method returns the value monthly fee back to the message sender.

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Calling a Class Method Account getAverageBalance average balance The average balance of all accounts is returned.

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Summary of Class and Object Icons Squared corners are used for a class and class methods. An instance method icon is drawn in a dotted line. Rounded corners are used for an object and instance methods.

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter 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 Account 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 Account objects is an aggregate information.

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Sample Instance Data Value Account SV129 Account SV506 Account SV008 current balance All three Account objects possess the same instance data value current balance. The actual dollar amounts are, of course, different

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Sample Class Data Value Account SV129 Account SV506 Account SV008 current balance Account minimum balance There is one copy of minimum balance for the whole class and shared by all instances.

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Variable and Constant Data Values There are two types of data values: Account SV129 minimum balance current balance account prefix 6427 opening balance A constant whose value must remain fixed over time. A variable whose value can change over time.

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Inheritance In object-oriented programming, we use a mechanism called inheritance to design two or more entities that are different but share many common features. First we define a class that contains the common features of the entities. Then we define classes as an extension of the common class inheriting everything from the common class. We call the common class the superclass and all classes that inherit from it subclasses. We also call the superclass an ancestor and the subclass a descendant.

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Account and Its Subclasses Account minimum balance Savings Checking minimum balance This class becomes the superclass of two subclasses… when (sub)classes inherit from it. Inherited components are not shown in the subclasses unless… the subclass(es) overrides them.

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Sample Inheritance Hierarchy Account Savings Checking SuperSaver RegularStudent Interest Bearing ATM Checking

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Having Fun with Java /* Program FunTime The program will allow you to draw a picture by dragging a mouse (move the mouse while holding the left mouse button down; hold the button on Mac). To erase the picture and start over, click the right mouse button (command-click on Mac). */ import javabook.*; class FunTime { public static void main(String[ ] args) { SketchPad doodleBoard; doodleBoard = new SketchPad(); doodleBoard.setVisible( true ); } Declare a name Create an object Make it visible

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Object Diagram for FunTime FunTime main SketchPad doodleBoard setVisible true

© 2000 McGraw-Hill Modified by C.W.Pang with author's permission Intro to OOP with Java--Wu Chapter Execution Flow of the FunTime Program SketchPad doodleBoard; doodleBoard = new SketchPad(); doodleBoard.setVisible( true ); SketchPad doodleBoard; doodleBoard doodleBoard = new SketchPad(); SketchPad doodleBoard.setVisible( true );