Saturday, November 10, 2007

Object Oriented Programming

Object-Oriented Programming consists of 3 primary ideas:
Data Abstraction and Encapsulation
Operations on the data are considered to be part of the data type
We can understand and use a data type without knowing all of its implementation details.Neither how the data is represented nor how the operations are implemented
We just need to know the interface (or method headers) – how to “communicate” with the object Compare to functional abstraction with methods.
Inheritance
Properties of a data type can be passed down to a sub-type – we can build new types from old ones.We can build class hierarchies with many levels of inheritance
Polymorphism
Operations used with a variable are based on the class of the object being accessed, not the class of the variable.Parent type and sub-type objects can be accessed in a consistent way.
Constructors
These are special instance methods that are called when an object is first created.
They are the only methods that do not have a return value (not even void).
They are typically used to initialize the instance variables of an object.
Accessors
These methods are used to access the object in some way without changing it
Usually used to get information from it.
Mutators
Used to change the object in some way
Since the instance variables are usually private, we use mutators to change the object in a specified way without needing to know the instance variables
B.setCharAt(0, ‘j’); // B == “jello there”
B.delete(5,6); // B == “jello here”
B.insert(6, “is “); // B == “jello is here”;
These methods change the contents or properties of the StringBuffer object

No comments: