Chapter 1 Introduction to Object-oriented Programming and Software Development Introduction to Object-Oriented Programming 2000 McGraw-Hl‖ Java--Wu Chapter 1-1
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 1 - 1 Chapter 1 Introduction to Object-oriented Programming and Software Development
Chapter 1 objectives After you have read and studied this chapter, you should be able to e Name the basic components of object-oriented programming e Differentiate classes and objects e Differentiate class and instance methods e Differentiate class and instance data values e Draw object diagrams using icons for classes objects and other components of object-oriented programming e Describe the significance of inheritance in object-oriented programs. Name and explain the stages of the software life cycle C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 1-2
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 1 - 2 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. Name and explain the stages of the software life cycle
Classes and objects r Object-oriented programs use objects r An object is a thing both tangible and intangible Account, Vehicle, Employee, eto r 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. r An object is called an instance of a class C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 1-3
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 1 - 3 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
Graphical Representation of an object The objects name appears on top of the sV129 Icon Account An icon for an object is The class name is the rounded rectangle placed inside the object icon customer1 The class name may be omitted when it is clear from the context which class the object belongs to C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 1-4
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 1 - 4 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
Graphical Representation of a Class The class name appears on top of the Account Icon An icon for a class is the tangle C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 1-5
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 1 - 5 Graphical Representation of a Class Account The class name appears on top of the icon. An icon for a class is the rectangle
Instance-of Relationship Employee Before you can create instances of a class the class must be defined The dotted line shows he instance-of relationship Bill Steve And The class name can be omitted since it is clear Employee Employee Employee which class these objects belong to C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 1-6
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 1 - 6 Instance-of Relationship Employee 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
Messages and methods r 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 the at understand the message you sent to them r a class or an object must possess a matching method to be able to handle the received message ra method defined for a class is called a class method and a method defined for an object is called an instance method r A value we pass to an object when sending a message is called an argument of the message C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 1-7
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 1 - 7 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
Sending a message Message deposit with the argument 250.00 is sent to chk-008 chk-008 Account deposit 250.00 -deposit Message name is usually omitted in the diagram 250.00 D deposit C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 1-8
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 1 - 8 Sending a Message Message deposit with the argument 250.00 is sent to chk-008. Account chk-008 deposit deposit 250.00 Message name is usually omitted in the diagram. deposit 250.00
Sending a Message and getting an Answer This message has no argument chk-008 Account getMonthlyFee monthly fee The method returns the value monthly fee back to the message sender C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 1-9
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 1 - 9 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
Calling a class method Account → >IgetAverageBalance average balance The average balance of all accounts is returned C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 1-10
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 1 - 10 Calling a Class Method Account getAverageBalance average balance The average balance of all accounts is returned