Object Oriented Programming

December 19, 2012

Object

Object is an instance of a class.  All objects have a state and behavior.

Class

Class is the blueprint from which individual objects are created

Inheritance

Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. In Java programming language, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses.

Interface

Methods form the object’s interface with the outside world. An interface is a group of related methods with empty bodies.  Interface separates implementation and defines the structure. It is useful when the implementation changes frequently.  Interface forms a contract between the class and the outside world.

Abstract Class

Abstract classes cannot be instantiated.  It can only be used as a super class for other classes that extend the abstract class.  Abstract classes are declared with keyword abstract.  Abstract class methods can have implementations. Abstract class’s methods can’t have implementation only when declared abstract.

Encapsulation

Encapsulation is inclusion within a program object of all the resources needed for the object to function.  It allows class to change its internal implementation without hurting the overall functioning of the system.

Polymorphism

Polymorphism is the ability to request that the same operations be performed by a wide range of different types of things.

Method overloading

Ability to define several methods all with the same name

Method overridding

Subclass overrides a specific implementation of a method that is already provided by one of its super classes.

References

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

http://www.codeproject.com/Articles/22769/Introduction-to-Object-Oriented-Programming-Concep#OOP


Convert JSON Object to String javascript

January 26, 2011

you can user browser native function JSON.stringify to do this

var foo = {};
foo.bar = "new property";
foo.baz = 3;

var jsonString = JSON.stringify(foo);

https://developer.mozilla.org/En/Using_JSON_in_Firefox

And IE8 also supports it – http://blogs.msdn.com/b/ie/archive/2008/09/10/native-json-in-ie8.aspx