Saturday, December 11, 2010

Object Oriented Programming|opps| Encapsulation | Polymorphism | Inheritance

Object Oriented Programming

OOP encapsulates data (e.g. numbers and objects) and methods (functions)

Information hiding is a key aspect of OOP

Implementation details are hidden from the user
(“we can drive a car without knowing how it is built”)

Java is “object oriented” language.

Encapsulation
Data and methods (ie functions) are stored together in a “class”. Code becomes modifiable, understandable, and portable.

In OOP the data and methods associated with objects are normally hidden from the users.

The details of the code are not available outside the class, the author decides what others can see, modify, and use.

Variables (data) can be Public, Protected, Private, Default.

Inheritance
Objects can inherit the properties of other objects.
Inheritance permits software reusability.
New classes can be created from old classes.
The attributes (data) and behavior (methods) of the old class are available to the new class.
New data and methods can be added to the new class also.
Inheritance allows you to write key pieces of code once and use it over and over.
Java support Multilevel Inheritance.
Java does not support Multiple Inheritance.

Polymorphism
You can write functions that behave differently depending on what kind of data is passed to them. E.g. you could make a sqrt function that would work with integers, floats, or even complex numbers.
Polymorphism allows you to avoid very complicated switch or if/else constructs that are required in other languages to treat special cases.
The same method name can be used in many different ways by different objects, this is especially interesting for inherited objects.

Abstraction

An abstraction denotes the essentials properties and behavior of an Object that differentiate it from other objects.

No comments:

Post a Comment