Object Oriented Programming language

  1. OOPs language revolves around classes, and objects.
  2. class is a kind of "blue print" from which objects can be generated
  3. Object is an "instance" of a class
  4. OOPs language bases on some fundamental properties like encapsulation, abstraction, data security, and inheritance.

Class & Objects:

In object oriented programming everything revolves around classes & objects. If you see real world, everything you see is an object. Let's take the example of building in which you are living currently, that itself is an object. It is an object because it has its own properties like rooms, fans, lights, etc.. every human being you see is an object. If you take a person who is a human being he has properties like legs, hands, eyes. He can also perform operations like running which internally uses legs property, he can also perform writing functionality with hands property, and can perform watching functionality with eyes property.
If you generalize a given set of objects that share a common properties and behavior , then that generalized thing is called as "class".
If you take the example of two persons, both share common properties like legs, hands, eyes etc.. In that case both of them belongs to a class called "HumanBeing" class.

Real examples of object & Class:

Example 1: Take the example of building in which you are residing. Is it a class or an object ? It is not a class it is an object because you can have construct similar kind of building in one more place. And more over its real thing that you are seeing. So, what will be the class for this building? The blue-print/ the building plan given by the engineer is the actual class for this building. That is because by using that plan you can generate n-number of same structured buildings. Let's say I asked you go into second room by giving that plan to you, then it will be a vague question as I cannot enter into second room of that plan as it s not a real entity it is just a model of how a real object is going to look like.
Example 2: Take the example of pen with which you are writing now. Is this a class or object? Its definitely an object because it's a real thing and you can use it now to write. And you can also see same kind of pen objects with others also. So all these pens that every one using to write are actually objects. So what is the class for these pen objects? If you see some molding factories where they will be using some steel moulds to create plastic cups, similarly there will be a mould to prepare pen also. Now that mould which we will be using to pour melted plastic into it to generate pens is actual class for all these objects. Now if you give that mould to anyone who has to capability to generate pens, then can create n-number of real pens which we can use to write.
Note: A class/object can internally refer to or can have n-number of other objects/ classes. For example if you take a building it has properties like"rooms", but this"room" itself can be object of another class called"RoomPlan". Again each room may contain an object called"fan" which itself is an object of type "FanClass".

Real world representation of objects - data - behavior:

Below is an example of an object called as "pen", where it has set of properties or states known as 'ink', 'capState opened or closed'. Outsiders cannot access this data directly since it is private data of the object. If outsiders want to access the data then they have to access through behaviors/ functions of the object. So only behavior is way of object to object communication mechanism in OOPs model. One can choose to give direct access to data also but whatever is private to object, such kind of data should be hold privately. In real world examples data is also known as 'states'. Object-data-behaviour

Software representation of Classes & objects:

This is how a class in software program looks like. Specifically in terms of Java programming this is how a class is written. In real world objects what we call "states [or] data' are called as 'variables' in programming concepts 'Variables' are the places we store the current state of the object 'Behaviors' in real world objects are 'functions' in programming concepts.
File name : Pen.java
public class Pen {
	public static final int OPEN = 1;
	public static final int CLOSED = 0;

	// the Pen class has
	// two fields
	public int ink;// states or variables
	public int cap_State; //states or variables
	// the Pen class has four methods  
	// these are behaviors [or] functions
	public void setInk(int newValue) {
		ink = newValue;
	}

	public void setCapState(int newValue) {
		cap_State = newValue;
	}

	public void startWriting(int decrement) {
		ink -= decrement;
	}

	public void openCap() {
		for(int i=0; i<3; i++){
			//turn one full cycle of cap
		}
		cap_State = OPEN;
	}    
}

Variables - data types - values:

Before analyzing above program let's understand what a variable is, what is a data type, and what is a value. Let's have a look at below example. Hold liquid
Now in the above example, bottle is the 'variable' which can hold only liquids. Liquid is the data type here since bottle can only allow liquid kind of data into it.
Note: Even though we can forcefully put solid items into bottle, for understanding purpose we presumed here that bottles allow only liquids.
Now we know that 'bottle' variable allows only 'liquid' data type. So we have put 'value' water into it. Now water is also liquid type.
Now similarly take an example of "int count = 10". Here 'count' is the variable name which holds the value. 'int' is the data type which tells that 'count' can take only integer values. And finally '10' is the value held in 'count' variable. Now you can see below comparison with water bottle and our programmed variables. Just like you have put 'water' into 'bottle', similarly we are putting value '10' into variable 'i'. Datatype

Top down versus bottom up Design approach:

Top down design approach:

1. This is followed by procedural and structured languages like c, pascal, pl/sql
2. In top down approach data will be given less priority, and logic or functions or procedures will be given high priority.
3. In top down approach, a big task is taken and will be cut down into smaller tasks to find the solution. If the the cut down task is still big, then it will be chopped down or cut down some more to divide in smaller tasks and, soulution will be found.
4. Eg: If you ask a"c" programmer to apply binary search on an array, then he will divide this task into 3 parts a. insert elements into array b. sort the array c. then search the array. Here programmer concentrates more on logic, than on the data.

Bottom Up design approach:

1. This is followed by OOPs languages like Java, .Net, C++ etc.
2. In bottom up data will be given high priority, rather than logics.
3. In bottom up approach, solution will be designed from an object. First we prepare data, functions of an object. Then construct class from that object. Then communicate with other classes. Then use all the classes in main function.
4. Eg: if you ask a"java" programmer to apply binary search on an array, then first he will think about data (array) and functions acting on that array(insert, sort, search). With that he will prepare a class for it. Then he will use that class in a main method one by one. So he is moving from bottom most element(object) to top most(classes).