Download presentation
Presentation is loading. Please wait.
Published byAlexys Hadden Modified over 10 years ago
1
By Waqas 1
2
2
3
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.
4
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.
5
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.
6
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.
7
By Waqas 7 So our car object look like the following figure. 10 mph (speed) 5 th gear (currentgear) red (color) Change gear brake accelerate Car Object
8
By Waqas 8
9
9 Encapsulation Packaging 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.
10
By Waqas 10
11
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
12
By Waqas 12 Object AObject B When object B wants object A to perform one of A's methods, object B sends a message to object A. message
13
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.
14
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.
15
By Waqas 15
16
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 cars state is independent and can be different from that of other cars. Class
17
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.
18
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.
19
By Waqas 19 Change gear 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.
20
By Waqas 20 Brake Change gear speed = 15 speed = 10 Color = redColor = blue gears = 4 Your CarMy Car These two car objects created from the car class.
21
By Waqas 21
22
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
23
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.
24
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
25
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.
26
By Waqas 26
27
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.
28
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.
29
By Waqas 29
30
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
31
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.
32
By Waqas 32 Car Sports Car Luxury Car
33
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.