Wednesday, June 20, 2012

Introduction to Object-Oriented Programming (OOP)

1. The basic building block of object-oriented programming are the class and object.
2. A class defines the available characteristics and behaviour of a set of similar objects.
3. A class is an abstract definition that is made concrete at run-time when objects based upon the class are instantiated and take on the class' behaviour.

There are 4 fundamental OOP concepts:

  1. Encapsulation ( n.封装;包装;密封 )
  2. Inheritance ( n.遗传;遗产;继承;继承物 )
  3. Polymorphism ( n.多形性;多态性 )
  4. Abstraction ( n.抽象;抽象概念;心不在焉 )




Encapsulation
Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. For this reason, encapsulation is also referred to as data hiding.

Encapsulation can be described as a protective barrier that prevents the code and data being randomly accessed by other code defined outside the class. Access to the data and code is tightly controlled by an interface.

The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this feature Encapsulation gives maintainability, flexibility and extensibility to our code.

Inheritance
Different kind of objects often have a certain amount in common with each other. Inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both, depending upon programming language support.

Object-oriented programming allows classes to inherit commonly used state and behaviour from other classes.

Polymorphism


Abstraction


<still in progress>

No comments:

Post a Comment