1 / 26

Chapter 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 Name the basic components of object-oriented programming. Differentiate classes and objects.

ahogan
Télécharger la présentation

Chapter 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 1 Introduction to Object-oriented Programming and Software Development Introduction to Object-Oriented Programming with Java--Wu

  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. Introduction to Object-Oriented Programming with Java--Wu

  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. Introduction to Object-Oriented Programming with Java--Wu

  4. The object’s name appears on top of the icon. An icon for an object is the rounded rectangle. The class name is 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. Graphical Representation of an Object SV129 Account Introduction to Object-Oriented Programming with Java--Wu

  5. The class name appears on top of the icon. An icon for a class is the rectangle. Graphical Representation of a Class Account Introduction to Object-Oriented Programming with Java--Wu

  6. Employee Before you can create instances of a class, the class must be defined. The dotted line shows the instance-of relationship. Steve Bill Andy The class name can be omitted since it is clear which class these objects belong to . Employee Employee Employee Instance-of Relationship Introduction to Object-Oriented Programming with Java--Wu

  7. Let’s Try One… • Draw an object diagram for a Person class and two Person objects (which are _______ of a class) • Person objects are Bubba and Tiny Introduction to Object-Oriented Programming with Java--Wu

  8. 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. Introduction to Object-Oriented Programming with Java--Wu

  9. 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 deposit Sending a Message Introduction to Object-Oriented Programming with Java--Wu

  10. This message has no argument. chk-008 Account getMonthlyFee monthly fee The method returns the value monthly fee back to the message sender. Sending a Message and Getting an Answer Introduction to Object-Oriented Programming with Java--Wu

  11. Account getAverageBalance average balance The average balance of all accounts is returned. Calling a Class Method Introduction to Object-Oriented Programming with Java--Wu

  12. Squared corners are used for a class and class methods. <Class Name> <result> <result> An instance method icon is drawn in a dotted line. <Object Name> <Class Name> Rounded corners are used for a class and class methods. Summary of Class and Object Icons Introduction to Object-Oriented Programming with Java--Wu

  13. 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. Introduction to Object-Oriented Programming with Java--Wu

  14. Let’s Try One… • Draw an object diagram of an Account class with the class method getAverageBalance and the instance methods deposit and withdraw • Now draw an Account object named Acct#235 Introduction to Object-Oriented Programming with Java--Wu

  15. SV506 SV129 SV008 Account Account Account current balance current balance current balance 1304.98 908.55 354.00 Sample Instance Data Value All three Account objects possess the same instance data value current balance. The actual dollar amounts are, of course, different. Introduction to Object-Oriented Programming with Java--Wu

  16. minimum balance There is one copy of minimum balance for the whole class and shared by all instances. SV506 SV129 SV008 100.00 Account Account Account current balance current balance current balance 1304.98 908.55 354.00 Sample Class Data Value Account Introduction to Object-Oriented Programming with Java--Wu

  17. minimum balance account prefix 100.00 6427 Account SV129 Account current balance opening balance 908.55 100.00 Variable and Constant Data Values There are two types of data values: A variable whose value can change over time. A constant whose value must remain fixed over time. Introduction to Object-Oriented Programming with Java--Wu

  18. 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. Introduction to Object-Oriented Programming with Java--Wu

  19. Question… • Look at page 25. • What are your thoughts on Figure 1.11? • Is an instance data variable OK for minimum balance? Should a instance data constant be used instead? Why or Why not? • Should we even use an instance value for minimum balance? Why or why not? Introduction to Object-Oriented Programming with Java--Wu

  20. This class becomes the superclass of two subclasses… minimum balance minimum balance 100.00 250.00 when (sub)classes inherit from it. the subclass(es) overrides them. Savings Checking Account and Its Subclasses Account Inherited components are not shown in the subclasses unless… Introduction to Object-Oriented Programming with Java--Wu

  21. Account Savings Checking Regular Student Interest Bearing ATMChecking SuperSaver Sample Inheritance Hierarchy Refer to Refer to Introduction to Object-Oriented Programming with Java--Wu

  22. Software Engineering and Software Life Cycle • The sequence of stages from conception to operation of a program is called software life cycle. Five stages are (page 30): • Analysis • Design • Coding • Testing • Operation and Maintenance • Software engineering is the application of a systematic and disciplined approach to the development, testing, and maintenance of a program. Introduction to Object-Oriented Programming with Java--Wu

  23. Declare a name Create an object Make it visible 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 ); } } Introduction to Object-Oriented Programming with Java--Wu

  24. doodleBoard FunTime SketchPad true setVisible main Object Diagram for FunTime Introduction to Object-Oriented Programming with Java--Wu

  25. doodleBoard Execution Flow of the FunTime Program SketchPad doodleBoard; doodleBoard = new SketchPad(); doodleBoard.setVisible( true ); SketchPad doodleBoard; doodleBoard = new SketchPad(); doodleBoard.setVisible( true ); SketchPad Introduction to Object-Oriented Programming with Java--Wu

  26. Let’s Try One… • Draw an object diagram of a Vehicle class and three Vehicle objects: Pinto, Camaro, and RangeRover Introduction to Object-Oriented Programming with Java--Wu

More Related