Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object Oriented Intro. Objectives Why Object-Oriented? Real-World Object/Programmed Objects? What we want in objects? Object Relationships?

Similar presentations


Presentation on theme: "Object Oriented Intro. Objectives Why Object-Oriented? Real-World Object/Programmed Objects? What we want in objects? Object Relationships?"— Presentation transcript:

1 Object Oriented Intro

2 Objectives Why Object-Oriented? Real-World Object/Programmed Objects? What we want in objects? Object Relationships?

3 The Data Type Problem Program Data Types double float String int long Problem Space Account Vehicle Student Branch Employee

4 The Data Type Problem w O-O Program Data Types Account Vehicle Student Branch Employee Problem Space Account Vehicle Student Branch Employee

5 What is an Object. An object has state. An object has behaviour. An object can be created. An object can be destroyed. Some objects are similar to other objects. Objects even when similar often differ in details. Objects interact with other objects.

6 What is an Programmed Object. Can represent both state and behaviour in one program element. Program element should be able to specify an inheritance relationship. You use variable/type declarations or references to represent the state of an object. You use methods to represent the behaviour of an object.

7 Example:Robot Simulation State. A robot simulation would retain information of where it is located on a grid. Behaviour. A robot simulation would have the capability to move() or perhaps perform actions like pickup() objects.

8 What is an Object-Oriented System. A set of interacting objects responding to an environment.

9 Problem-Solving the O-O Way. Encapsulation. Bundling of state information and behaviour. It is possible (and desirable) to hide the state information from all other elements of the program. Inheritance Ability to define one class of objects in terms of another class of objects (Class X is a special case of Class Y). element should be able to specify an inheritance relationship. Polymorphism. Allows you to treat different classes of objects in a similar manner to simplify programming.

10 Encapsulation double x; State: Exponent Exponent Sign Fraction Fraction Sign Behaviour: Addition Subtraction Division Multiplication Instantiation Activities Destruction Activities.

11 Encapsulation A Key benefit of the object-oriented approach. By hiding internal data of an object from the rest of the program (system) you make it less likely that a statement will accidentally change the data incorrectly. By associating data with only one program element, it means you will not have to search as many lines of code for debugging.

12 Encapsulation accountNo balance getAccountNo () setBalance () getBalance () setAccountNo() User

13 Inheritance Specification of an is-a relationship. A car is-a type of vehicle. A salaried employee is-a type of employee. A keyboard is-a type of device. Allows us to separate out elements that are similar between different classes of objects from those that are specific to individual classes.

14 Composition Specification of an has-a relationship. A car has-a engine. A salaried employee has-a payment history. A pc has-a keyboard. Allows us to compose new classes out of existing classes.

15 Other relationships. There are other relationships (association) but these will be covered later.

16 Questions. Name one capability in problem-solving allowed with object-oriented programs that is not available in traditional languages? Give a simple definition of an object-oriented system? What is the purpose of encapsulation? What are the benefits of encapsulation?


Download ppt "Object Oriented Intro. Objectives Why Object-Oriented? Real-World Object/Programmed Objects? What we want in objects? Object Relationships?"

Similar presentations


Ads by Google