The Great Symbian

Anything under the sun goes here!

· OBJECT-ORIENTED PROGRAMMING

- is a method of implementation in which programs are organized as cooperative collections of objects, each of which represents an instance of some class, and whose classes are all members of one or more hierarchy of classes united via inheritance relationships.

OOP (Object-oriented programming) = encapsulated state + inheritance

Object-Oriented Design
– Focuses on object and classes based on real world scenarios
– Emphasizes state, behavior and interaction of objects
– Advantages:

·Faster development

·Increased quality

·Easier maintenance

·Enhanced modifiability

·Increase software reuse


· ENCAPSULATION
- Combine the data and the operations
- Enclosing of both variables and functions
- Keep details of the data and operations from the users of the ADT
- Once you have created an ADT for complex numbers, say Complex, you can use it in the same way like well-known data types such as integers.
– Principle of hiding design or implementation information not relevant
to the current object


· OBJECT
- An entity with unique identity that encapsulate state
- state can be accessed in a controlled way from outside
- The access is provided by means of methods (procedures that can directly access the internal state)


· CLASS
- A specification of objects in an incremental way
- By inheriting from other classes
- And specifying how its objects (instances) differ from the objects of the inherited classes


·CLASS VARIABLE
– Behave like a global variable
– Can be accessed by all instances of the class


·CLASS INSTANTIATION
The process of creating objects from a class is called instantiation. So an object is always an instance of a class which represents the blueprint.
The object is constructed using the class and must be created before being used in a program.
Objects are manipulated through object references (also called reference values or simply references)

Creating objects in Java usually follow these steps:

1- Declaration of a reference variable of the appropriate class which will store a reference to the object.
For example:

//declaring my car
Car myCar;

// declaring my father's car
Car myFatherCar ;

Or combined if they belong to the same appropriate class, separated by a comma:

//declaring my car and my father's car
Car myCar, myFatherCar ;


2- Creating an object
This involves using the new operator and calling a constructor to create an instance of the class.
The new operator returns a reference to a new instance of the Car class.
The reference can be assigned to a reference variable of the appropriate class, here: myCar and myFatherCar.

// instantiating myCar from the class Car,
//having the String "black" as parameter value.
myCar = new Car("black");

// instantiating myFatherCar from the class Car
//having the String "blue" as parameter value.
myFatherCar = new Car("blue");


Each object has a unique identity and has its own copy of the fields declared in the class.

The purpose of calling the constructor on the right side of the new operator is to initialize the newly created object.

The declaration and initialization can be combined:

// declaring and instantiating myCar from the class Car,
//having the String "black" as parameter value.
Car myCar = new Car("black");

// declaring and instantiating myFatherCar from the class Car
//having the String "blue" as parameter value.
Car myFatherCar = new Car("blue");


·METHOD
– Describes the behavior of an object
– Also called a function or a procedure
– Student registration system example


· METHOD DECLARATION

To declare methods we write,
(*) {
*
}
– where,
can carry a number of different modifiers
can be any data type (including void)
can be any valid identifier
::= [,]


· STATIC METHOD

public class StudentRecord {
private static int studentCount;
public static int getStudentCount(){
return studentCount;
}
}
– where,
· public- means that the method can be called from objects outside the class
· static-means that the method is static and should be called by typing,
[ClassName].[methodName]. For example, in this case, we call the method
StudentRecord.getStudentCount()
· int- is the return type of the method. This means that the method should return a
value of type int
· getStudentCount- the name of the method
· ()- this means that our method does not have any parameters


· PARAMETER PASSING

- Pass by Value refers to passing a constant or a variable
holding a primitive data type to a method, and

- Pass by Reference refers to passing an object
variable to a method. In both cases a copy of the variable is passed to the method.

0 comments:

FEEDS

Add to Google Reader or Homepage