Presentation is loading. Please wait.

Presentation is loading. Please wait.

©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.

Similar presentations


Presentation on theme: "©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development."— Presentation transcript:

1 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development

2 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Topics Object-oriented programming classes and objects inheritance Unified Modeling Language Software Development cycle

3 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Programming Programs are used to specify what a computer should do Procedural a recipe for what needs to be done step-by-step instructions Object-oriented program is a model work gets done as different components of the model interact We'll take the object-oriented approach

4 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Classes and Objects Object-oriented programs use objects. An object is a thing, either tangible or intangible. Account, Vehicle, Employee, etc. are examples of possible objects. An object is comprised data operations that manipulate the data

5 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Classes and Objects 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 created following the model provided by the class. An object is an instance of a class.

6 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Classes and objects A class serves as a template from which an object can be constructed Like a cookie cutter - all cookies have the same shape but they are distinct objects Like a factory - all the objects coming off an assembly line are similar but they are different objects Like data on a form - each object has the same type of data but the actual information is different

7 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 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. Each class can have any number of methods corresponding to the messages it can receive

8 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Messages and Methods 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.

9 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Unified Modeling Language When you get ready to write a program, you need a way to plan what needs to be done In a procedural approach to programming, you might draw a flow chart In object-oriented programming, we make UML diagrams show the features of a class show relationships between classes show relationships between objects

10 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Object Diagrams A graphical representation of an object. An object diagram can contain Object name Class name Object data

11 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Sample Object Diagrams UML notation for objects and classes: Two Bicycle objects with the names Moto-1 and Moto-2 and one Customer object with the name Jon Java.

12 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Class Diagrams A class diagram is graphical representation of a class. It contains the name of the class and possibly information about its information and data

13 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Communicating with Objects One-way communication: Sending the message walk to a Robot object. These are called procedures in some programming languages.

14 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Two-way communication: The result distance is returned to the sender of the message. These are called function in some programming languages

15 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Sometimes a class needs to maintain some information about the class as a whole rather than about a particular object Similarly, you may need to send messages to the class itself rather than to a particular object.

16 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. An example of a class method: The maximum possible speed of all Robot objects is returned by the class method getMaximumSpeed.

17 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 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.

18 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Class and Instance Data Values 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 aggregate information.

19 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. An example of an instance data value: Three Account objects possess the same data value current balance, but the actual dollar amounts differ.

20 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Class data example Three Account objects sharing information (minimum balance = $100) stored as a class data value.

21 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Another example of class data Three Cafeteria objects sharing the same opening and closing times, stored as class data values.

22 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. An example of inefficient program design: Three Account objects duplicating information (minimum balance = $100) in instance data values. Why store the same information in multiple places if it always should be the same?

23 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Object Diagrams Revisited Four types of data values: class variable, class constant, instance variable, and instance constant.

24 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 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. Inheritance allows programmers to re- use the work put into developing one class when developing similar ones

25 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Inheritance 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.

26 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Inheritance 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. Or we can call the superclass the parent class and the subclass the child class.

27 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Inheritance Example A superclass Account and its subclasses Savings and Checking.

28 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Inheritance Hierarchy A UML diagram showing the inheritance hierarchy for different types of students.

29 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Software Engineering Software engineering is the application of a systematic and disciplined approach to the development, testing, and maintenance of a program.

30 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 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

31 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Software Life Cycle Analysis phase: Study the problem. Determine if a solution is possible. Develop a requirements specification describing the features of the program.

32 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Software Life Cycle Design phase: Turn the requirements specification into a detailed program design. Fully define all classes and objects, including how they behave and communicate between themselves.

33 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Software Life Cycle Coding phase: Implement the detailed design into an actual program.

34 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Software Life Cycle Testing phase: Run the program using different data sets to verify the program works properly. Unit testing: Test classes individually. Integration testing: Test that the classes work together correctly.

35 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Software Life Cycle Operation phase: Program is put into use. Software maintenance accounts for approximately 70% of the cost of the software.


Download ppt "©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development."

Similar presentations


Ads by Google