Saturday, April 17, 2010

Classes in OOP

A class is a blueprint or prototype from which objects are created. This section defines a class that models the state and behavior of a real-world object. It intentionally focuses on the basics, showing how even a simple class can cleanly model state and behavior.



The best thing about OOP is , When we look around the world, we can relate things to OOP. We can find many Objects of the same type or Class. For example, your CAR. It is only one of the millions running around the world.

In terms of OOP, your car is an instance of the class 'cars'. Each car will have a state, and it will have behavior as well. However, the state and behavior of one car is not dependent on the state and behavior of other cars. An example of a behavior a car will have is braking, while the state of the car could be having four wheels.

In OOPs, it is possible to have a large number of objects with identical attributes. The advantage of processing objects which are the same type is that you can generate a diagram for them. So, the class is a diagram that contains the methods and variables which are related to a specific group of objects.

Once a class has been created, one can create innumerable instances from it. Each one would have its own set of variables to play around with. It now depends on the the System to allocate necessary resources for this class.

A  class has it's own set of methods, the ways that tell the objects to behave in a particular manner.

No comments: