Documente Academic
Documente Profesional
Documente Cultură
What is an Object?
Encapsulation The Benefits of Encapsulation
1.1
Overloading
Overriding Benefits of OOPS
1.2
Objectives
After studying this chapter, the students should be able to: Understand the concepts of Object Oriented Methodology Abstraction, Encapsulation, Objects, Classes and Inheritance.
Object- Oriented Programming An Introduction Object-Oriented Programming (OOP) has been developed, based on real life itself, to easily and efficiently remove the problems associated with procedural programming. The first achievement of OOP towards better design and maintenance is the removal of ambiguity, OOP handles is the problem of non-flexibility of code.
Rel. Feb. 2000 1.3 STG Intl. Ltd.
What is an Object? Objects are software bundles of data and related procedures. The following illustration is a common visual representation of a software object:
An Object
Rel. Feb. 2000 1.4 STG Intl. Ltd.
Encapsulation
Your Bicycle
1.5
The Benefits of Encapsulation Encapsulating related variables and methods into a neat software bundle is a simple yet powerful idea that provides two primary benefits to software developers: Modularity Information hiding What Are Messages? Software objects interact and communicate with each other by sending messages to each other. When object A wants object B to perform one of its methods, object A sends a message to object B.
1.6
Messaging
Rel. Feb. 2000 1.7 STG Intl. Ltd.
1.8
What are Classes? A class is a blueprint or prototype that defines the variables and the methods common to all objects of a certain kind.
Rel. Feb. 2000 1.9 STG Intl. Ltd.
A Class
1.10
1.11
In the real world its obvious that classes are not themselves the objects that they describe.
Then also occurs because many people use the term object inconsistently and use it to refer to both classes and instances.
The main difference between a class and an object is that objects are tangible, but a class is always intangible. You cant see a class but you can always see an object.
The Benefits of Classes Objects provide the benefit of modularity and information hiding. Classes provide the benefit of reusability
1.12
What is Inheritance?
Classes inherit state and behavior from their superclass. Inheritance provides a very helpful concept of code reusability.
Hierarchy of Classes
Rel. Feb. 2000 1.13 STG Intl. Ltd.
The Benefits of Inheritance Subclasses provide specialized behaviors from the basis of common elements provided by the superclass. Through the use of inheritance, programmers can reuse the code in the superclass many times. Programmers can implement superclasses that define "generic" behaviors (called abstract classes). The essence of the superclass is defined and may be partially implemented but much of the class is left undefined and unimplemented. Other programmers fill in the details with specialized subclasses. Abstraction In java, classes are used to categorize data in order to model real life systems. Abstraction is this process of categorizing data.
Rel. Feb. 2000 1.14 STG Intl. Ltd.
Abstraction
Rel. Feb. 2000 1.15 STG Intl. Ltd.
Polymorphism Polymorphism may be defined as the ability of related objects to respond to the same message with different, but appropriate, actions.
Shape Draw ( )
Polymorphism
Rel. Feb. 2000 1.16 STG Intl. Ltd.
Dynamic Binding Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run-time. It is associated with polymorphism and inheritance.
Overloading
In Object Oriented Programming if a method depending on some information does different job at different times that method is overloaded .Overloading is nothing but a kind of polymorphism.
Rel. Feb. 2000 1.17 STG Intl. Ltd.
Example:
1.18
Overriding Inheritance is a mechanism of inheriting the traits of parents but some times some properties should be modified according to the need like a son inherits legs from his parents but his walking style is different. This is Overriding. It is again a kind of polymorphism and very important in terms of dynamic decisions.
Benefits of OOP
Through inheritance, we can eliminate redundant code and extend the use of existing classes.
We can build programs from the standard working modules, which communicate with one another, rather than having to start writing the code from scratch. This leads to saving of development time and higher productivity.
1.19 STG Intl. Ltd.
The principle of data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the program. It is possible to have multiple instances of an object to coexist without any interference. It is possible to map objects in the problem domain to corresponding objects in the program. It is easy to partition the work in a project based on objects. The data-centered design approach enables us to capture more details of a model in implementable form. Object-oriented systems can be easily upgraded from small to large systems. Message passing techniques for communication between objects makes the interface descriptions with external systems much simpler. Software complexity can be easily managed.
1.20 STG Intl. Ltd.