• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
 An Introduction to ObjectOriented Programming
This introductory chapter covers the basics of object oriented program-ming. It also serves to introduce the terminology used throughout thisbook. What is object oriented programming? What are the basic conceptsused in object oriented programming? What are the basic classificationsand definitions used for various concepts in object oriented program-ming? These questions on object oriented programming are answered inthis introductory chapter.
WHAT IS OBJECT ORIENTED PROGRAMMING?
Object oriented programming has been the most popular programmingparadigm for more than last two decades. It has been the subject of active research for more than three decades, and is well-accepted and widely used in the software industry today. What is object oriented programming? [Mossenbock 1993]
1
providesthe following definition: 
Object oriented programming means program- ming with abstract data types (classes) using inheritance and dynamic binding 
.
1
[Mossenbock 1993] Hanspeter Mossenbock, Object-Oriented Programming inOberon-2, Springer-Verlag, 1993.
 
60 Tips for Object Oriented Programming 
PROCEDURAL PROGRAMMING VERSUS OBJECT ORIENTEDPROGRAMMING
The traditional programming methodology encourages us to think aboutsolving problems by decomposing the programs into various procedures.Procedures provide specific functionality and operate on (global) data.Computers execute instructions sequentially and operate on data; theprocedural approach provides a layer of abstraction over the machineby providing higher level procedures. So, procedural approach appearsto be the most natural way of solving problems. However, programmingon large scale with procedural approach may lead to lots of problems.Huge applications written using procedural style tend to be fragile, andit is difficult to maintain or extend the code.Object orientated programming methodology encourages us to givecentral importance to data (instead of procedures). Object orientationprovides support for modelling solutions at higher level in terms of classes,relationship between classes, inheritance and dynamic binding. Insteadof writing code that solves specific problems, generalized classes are written under object oriented approach, and then specific code is pro- vided to solve the problem. This provides the basis for writing reusableand extensible software.To summarize, object oriented programming provides a higher levelof abstraction than procedural programming. Traditional procedural pro-gramming supports writing software that solves specific problems; ob-ject oriented programming provides support for writing software that isalso extensible, reusable and maintainable.
CLASS
 A class declaration is a logical abstraction which defines a new type thatdetermines what an object of that type will look like. Object orientedprogramming enables creation of self-contained types with classes. Thishelps in reusability, maintenance, abstraction and other desirable prop-erties for the software. For example, if you make changes to the class, itdoes not necessarily imply that you have to change the code using thatclass.From programming point of view, a class refers to a programmerdefined data type together with a set of operations that can be per-
 
 An Introduction to Object Oriented Programming 
!
formed on it. Combining the data with the operations on it leads to
encapsulation 
.
Abstraction 
refers to hiding the internal details and ex-posing only the relevant details of the class to the external users. Throughencapsulation, abstraction is achieved.
OBJECTS
 An object is
instantiated 
from a class type. It is possible to create any number of objects from a class type.Every object has three aspects associated with it:
space 
,
identity 
and
behaviour 
. A class is a logical entity and doesnt occupy any space dur-ing the program execution. An object declaration creates a physical en-tity of a class type, so, an object is always associated with space. Every object has a unique identity. Since every object occupies some memory,objects have an address; also objects can have names associated with it.In this way, every object can be uniquely identified in a program. Every object has a set of behaviour (methods) associated with it.
METHODS AND FIELDS
 A class contains both data and functions operating on it. Member func-tions are known as
methods 
and data members are known as
 fields 
. When a method is invoked on an object, it is said that the object ispassed with a
message 
.The members (function or data) that are common to all the objects of a class can be provided in the class itself. Such class members are alsoknown as
static members 
(static functions or static data). For example, aclass might need to keep track of the number of objects created fromthat class. A
static data member 
can be used as a counter that will beincremented or decremented whenever a new object is created or de-stroyed. A function that is used to increment, decrement or access the value of that counter will be a
static function 
.
ACCESS SPECIFIERS
 Access specifiers determine the accessibility of a class member. Thereare two important access specifiers: public and private. Private members
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...