Presentation is loading. Please wait.

Presentation is loading. Please wait.

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 1 Lecture 1 Introduction to Computers and Object-

Similar presentations


Presentation on theme: "©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 1 Lecture 1 Introduction to Computers and Object-"— Presentation transcript:

1 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 1 Lecture 1 Introduction to Computers and Object- Oriented Programming

2 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 2 Computer Architecture CPU Output Devices Output Devices Commu- nication Devices Commu- nication Devices Input Devices Input Devices RAM Storage Devices Storage Devices

3 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 3 Programming Languages Three levels of programming languages: –Machine Languages –Machine language instructions are binary coded and very low level. –Assembly Languages –Assembly language allows symbolic programming. Requires an assembler to translate assembly programs into machine programs. –High-level Languages –High-level language provides a very high conceptual model of computing. Requires a compiler to translate high-level pograms into assembly programs.

4 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 4 What is Programming A program is a sequence of instructions that will be executed by a computer. To write a program, you need to learn a language that can be converted into a form that the computer can understand –Early languages were designed to make this conversion easy –Modern languages are designed for the convenience of the programmer Java is a high-level object-oriented language

5 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 5 Types of Languages Procedural languages approach programming as a sequence of operations on data Object-oriented languages model the world as a collection of objects –every object has properties that represent its state –objects have behavior associated with them

6 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 6 Classes and Objects An object is a thing, (tangible or intangible). –Account –Vehicle –Employee To create an object inside the computer program, we must first provide a definition for each particular kind of object (called a class) –how it behaves –what kind of information represents it An object is called an instance of a class.

7 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 7 Graphical Representation of a Class The notation we used here is based on the industry standard notation called UML, which stands for Unified Modeling Language. We use a rectangle to represent a class with its name appearing inside the rectangle. Example: Account Motorcycle

8 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 8 Graphical Representation of an Object We use a rectangle to represent an object and place the underlined name of the object inside the rectangle. Example: SV198 This is an object named SV198.

9 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 9 An Object with the Class Name : This notation indicates the class which the object is an instance. This tells an object SV198 is an instance of the BankAccount class. Example: SV198 : BankAccount

10 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 10 Sending a Message deposit 250.00 Message deposit with the argument 250.00 is sent to a BankAccount object SV198. SV198 : BankAccount To instruct an object to perform a task, we send a message to it. The class an object belongs to must possess a matching method to be able to handle the received message. A value we pass to an object when sending a message is called an argument.

11 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 11 Sending a Message and Getting an Answer current balance getCurrentBalance() Ask for the current balance of this particular account. SV198 : BankAccount The current balance of SV198 is returned.

12 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 12 Calling a Class Method maximum speed MobileRobot getMaximumSpeed() Ask for the maximum possible speed for all MobileRobot objects is returned.

13 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 13 Classes and Objects A class is a template that defines what properties and behavior a particular type of object has –Class diagram An object is an instance of a class –You can have many instances of a class –Object diagram :

14 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 14 Data and Methods Properties of an object are represented by data values Behavior of objects is implemented by the methods in a class –Send a message to an object by calling one of its methods Two types of data and methods –Class methods and data are shared by all objects –Instance data and methods are associated with a particular object

15 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 15 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.

16 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 16 SV098 : BankAccountSV211 : BankAccountSV129 : BankAccount Sample Instance Data Value current balance 908.55 1304.98 354.00 All three BankAccount objects possess the same instance data value current balance. The actual dollar amounts are, of course, different.

17 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 17 Object Icon with Class Data Value When the class icon is not shown, we include the class data value in the object icon itself. SV129 : BankAccount current balance 908.55 minimum balance 100.00

18 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 18 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.

19 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 19 A Sample Inheritance Here are the superclass Account and its subclasses Savings and Checking. Account Checking Savings

20 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 20 Inheritance Hierarchy An example of inheritance hierarchy among different types of students. Student Graduate Undergrad Commuting Law Resident Masters Doctoral


Download ppt "©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 1 - 1 Lecture 1 Introduction to Computers and Object-"

Similar presentations


Ads by Google