Objectives Why Object-Oriented? Real-World Object/Programmed Objects? What we want in objects? Object Relationships?
The Data Type Problem Program Data Types double float String int long Problem Space Account Vehicle Student Branch Employee
The Data Type Problem w O-O Program Data Types Account Vehicle Student Branch Employee Problem Space Account Vehicle Student Branch Employee
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.
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.
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.
What is an Object-Oriented System. A set of interacting objects responding to an environment.
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.
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.
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.
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.
Other relationships. There are other relationships (association) but these will be covered later.
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?