OOP Concepts

An object is a software bundle of related state (attributes) and behavior (methods). Software objects are often used to model the real-world objects that you find in everyday life.

Object-Oriented Programming is just a programming paradigm based on this concept of ‘”everything is object”. A class is a blueprint or prototype from which objects are created. A class models the state and behavior of a real-world object.

In definition of a class, we can decide which attributes or methods are only locally used, i.e. private, which can be exposed to others, i.e. public. This is called data encapsulation. It allows data hiding and protection of coding corruption.

For example, a car can be described as a specific implementation of a more general ‘class’ of a thing, called a vehicle. We model this relationship in software with classes by defining a Vehicle class and a Car class. In class Vehicle, we have speed, carry of people, etc.which would be all the behaviors common to most of different types of vehicles, e.g. planes, trains, etc.. It might not make sense in our software to redefine the basic essence of speed over and over again for each different type of vehicle. Instead, we define it once in Vehicle, and then when we define Car (child class), we simply indicates that it inherits (extends) the base definition from Vehicle (parent class). Car is said to specialize the general Vehicle definition. This is how inheritance works in class definition.

Another key concept is polymorphism, which describes the idea that a general behavior from a parent class can be overridden in a child class to give it more specifics. Say we define a method StartEngine() in Vehicle, the same named method should be implemented differently in Car and Plane, since each starts engine differently.

Ref:

1. http://docs.oracle.com/javase/tutorial/java/concepts/index.html

2. wikipedia: oop

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s