by waqas 1. 2 3 over the many years the people have studied software-development approaches to...

33
By Waqas 1

Upload: alexys-hadden

Post on 31-Mar-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 1

Page 2: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 2

Page 3: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 3

Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most reliable, and produce the best software.

Of all the known approaches to developing software, one approach, called the object-oriented approach, has repeatedly proven itself to be the best approach for a large scale software applications.

Page 4: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 4

Object-oriented programming focuses on the development of self-contained software components, called objects.

An object is a software bundle of variables and related methods.

Objects are key to understanding object oriented technology. You can look around you now and see many examples of real-world objects: dog, car, television set, bicycle.

Page 5: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 5

All these real world objects have two characteristics: state and behavior. For example car have states (current gear, number of gears, color, number of wheels) and behavior (braking, accelerating, slowing down, changing gears ) etc.

Page 6: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 6

Software objects are modeled after real-world objects in that they too have state and behavior. A software object maintains its state in one or more variable. A software object implements its behavior with methods.

variables(state)

object

methods(behavior)

Software objects are modeled after real-world objects in that they too have state and behavior. A software object maintains its state in one or more variable. A software object implements its behavior with methods.

Page 7: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 7

So our car object look like the following figure.

10 mph(speed)

5th gear(currentgear)

red(color)

Change gear

brake

accelerate

Car Object

Page 8: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 8

Page 9: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 9

EncapsulationPackaging an object's variables within the protective custody of its methods is called

Encapsulation.

A powerful benefit of encapsulation is the hiding of implementation details from other objects. This means that the internal portion (variables) of an object has more limited visibility than the external portion (methods). This will protect the internal portion against unwanted external access.

Page 10: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 10

Page 11: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 11

A single object generally is not very useful. A large application may require many objects. Your car standing in garage is incapable of any activity. The car is useful only when another object (You) interacts with it.

Software objects interact and communicate with each other by sending messages to each other.

Messages

Page 12: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 12

Object A Object B

When object B wants object A to perform one of A's methods, object B sends a message to object A.

message

Page 13: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 13

Sometimes, the receiving object needs more information so that it knows exactly what to do.For example, when you want to change gears on your car, you have to indicate which gear you want. This information is passed along with the message as parameters.

Page 14: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 14

“Message passing” is just another name of “method calling”. When an object sends another object a message, it is really just calling a method of that object. The message parameters are actually the parameters of the method.

Page 15: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 15

Page 16: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 16

In the real world, we often have many objects of the same kind. For example, my car is just one of many cars in the world. Using object-oriented terminology, we say that my car object is an instance of the class of objects known as cars.

Cars have some state (current gear, one engine, four wheels) and behavior (change gears, brake) in common. However, each car’s state is independent and can be different from that of other cars.

Class

Page 17: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 17

When building cars, manufacturers take advantage of the fact that cars share characteristics, building many cars from the same blueprint. It would be very inefficient to produce a new blueprint for every individual car manufactured.

In object-oriented software, it's also possible to have many objects of the same kind that share characteristics. Classes provide the benefit of reusability.

Page 18: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 18

we can take advantage of the fact that objects of the same kind are similar and we can create a blueprint for those objects. A software blueprint for objects is called a class.

“A class is a blueprint, or prototype, that defines the variables and the methods common to all objects of a certain kind.”

Page 19: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 19

Changegear

Brake

Number of gears

Number of wheels

Car object

After you've created the car class, you can create any number of car objects from the class. Each instance gets its own copy of all the instance variables defined in the class.

Page 20: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 20

Brake Brake

Changegear

Changegear

speed = 15 speed = 10

Color = red Color = blue

gears = 4 gears = 4

Your Car My Car

These two car objects created from the car class.

Page 21: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 21

Page 22: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 22

Inheritance is one of the most crucial concepts in object-oriented programming, and it has a direct effect on how you design and write Java classes. Inheritance is a powerful mechanism that allows a class to inherit functionality from an existing class.

For example, sports car, luxury car, both are kinds of cars.

Inheritance

Page 23: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 23

Car

Sports Car Luxury Car

In object-oriented terminology, sports cars and luxury cars are subclasses of car class. Similarly, the car class is the superclass of luxury car and sports car.

Page 24: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 24

Each subclass inherits all variables from the superclass. Sports cars and luxury cars both inherits four wheels, gears etc. Also, each subclass inherits methods from the superclass. Luxury cars and sports cars share some behaviors: braking and changing speed, for example.

However, subclasses are not limited to the state and behaviors provided to them by their superclass. Subclasses can add

Page 25: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 25

variables and methods to the ones they inherit from the superclass. Sports cars have two seats and, some sports cars have an extra set of gears.

Subclasses can also override inherited methods and provide specialized implementations for those methods. For example, if you had a sports car with an extra set of gears, you would override the "change gears" method so that the rider could use those new gears.

Page 26: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 26

Page 27: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 27

Polymorphism is the ability to assume different forms. In object-oriented programming, this refers to the ability of objects to have many methods of the same name, but with different forms.

Polymorphism

Polymorphism is a phenomena in which the parent class object call the appropriate overridden method of child class at run time.

Page 28: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 28

Caller

A

B

C

Exchange decide at call time to which department it may transfer the call according to the request of the caller.

Page 29: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 29

Page 30: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 30

The process of picking out (abstracting) common features of objects and procedures.

Abstraction

Conversion of real world entity to computer based entity by extracting relevant information of that entity.

or

Page 31: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 31

A programmer would use abstraction, for example to note that if two functions performs almost the same task they can be combined to a single function.

Suppose you have a car class and two sub classes sports car, luxury car both sub classes have methods for change gear. To implement abstraction this method should be available in car class.

Page 32: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 32

Car

SportsCar

LuxuryCar

Page 33: By Waqas 1. 2 3 Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most

By Waqas 33

To implement abstraction the programmer would declare all methods and variables common to all child classes in the super class so that any child class has access to these variables and methods without declaring explicitly.

This techniques results in to build more abstract and powerful classes