Object-oriented programming

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by TakuyaMurata (talk | contribs) at 02:29, 1 February 2004. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Jump to navigation Jump to search


Object-oriented programming (OOP) is a computer programming paradigm that emphasizes the following aspects:

  • Objects - packaging data and functionality together into units within a running computer program; objects are the basis of modularity and structure in an object-oriented computer program.
  • Abstraction - combining multiple smaller operations into a single unit that can be referred to by name.
  • Encapsulation - separating implementation from interfaces.
  • Polymorphism - using the same name to invoke different operations on objects of different data types.
  • Inheritance - defining objects data types as extensions and/or restrictions of other object data types.

Notes: Abstraction is important to but not unique to OOP. Reusability is a benefit often attributed to OOP.

OOP is often called a paradigm rather than style or type of programming to emphasize the point that OOP can change the way software is developed, by changing the way that programmers and software engineers think about software.

Basics of object-oriented programming

The fundamental aspect of object-oriented programming is that a computer program is composed of a collection of individual units, or objects. To make the computation happen, each object is capable of receiving messages and sending messages to other objects. In this way, messages can be handled by one chunk of code but may be done so by another code block seamlessly. It is claimed then that this gives more flexibility over step-by-step programming or imperative programming as known in the field of computer science. Thus, the challenge in OOP programmers face is how to distribute responsibility over objects, or classes--one of popular implementation schemes.

Proponents of OOP also claim that OOP is more intuitive and, for those new to computer programming, is easier to learn than a traditional way--breaking the computation into procedures. In OOP, objects are simple, self contained and easily identifiable. This modularity allows the program parts to correspond to real aspects of the problem and thereby to model the real world. Indeed, object-oriented programming often begins from a written statement of the problem situation. Then by a process of inserting objects or variables for nouns, methods for verbs and attributes for adjectives, a good start is made on a framework for a program that models, and deals with, that situation.

The majority of the computer programmers agree that OOP is a major advance on the previous complexities of procedure based methods, as its popularity attests to the fact, and OOP can be major advantage in large projects where procedural methods tended to develop very complicated conditional loops and branches, difficult to understand and to maintain.

Implementation techniques

OOP with procedural languages

In procedural languages, OOP often appears as a form where data types are extended to behave like an object in OOP, very similar to an abstract data type with an extension such as inheritance. Each method is actually a subprogram which is syntactically bound to a class.

Definition

The definitions of OOP are disputed. In the most general sense, object-oriented programming refers to the practice of viewing software primarily in terms of the "things" (objects) it manipulates, rather than the actions it performs. Other paradigms such as functional and procedural programming focus primarily on the actions, with the objects being secondary considerations; in OOP, the situation is reversed.

Widely-used terminology distinguishes object-oriented programming from object-based. The former is held to include inheritance (described below), while the latter does not. See Dispute over the definition of object-oriented programming

Class-based models

The most popular and developed model of OOP is a class-based model, as opposed to an object-based model. In this model, objects are entities that combine both state (i.e., data) and behavior (i.e., procedures, or methods). An object is defined by a class, which is a definition, or blueprint, of all objects of a specific type. An object must be explicitly created based on a class and an object thus created is considered to be an instance of that class. An object is similar to a structure, with the addition of method pointers, member access control, and an implicit data member which locates instances of the class (i.e.: actual objects of that class) in the class hierarchy (essential for runtime inheritance features).

Inheritance

Inheritance, (also inheritance (computer science) for the basic idea): One object's data and/or functionality may be based on those of other objects, from which the former object is said to inherit. This allows commonalities among different kinds of objects to be expressed once and reused multiple times. Inheritance is also commonly held to include subtyping, whereby one type of object is defined to be a more specialised version of another type (see Liskov substitution principle), though non-subtyping inheritance is also possible. Inheritance is typically expressed by describing classes of objects arranged in an inheritance hierarchy reflecting common behavior.

Prototype-based models

SELF, a programming language developed by Sun Microsystems is an instance.

Object-based models

Object-based programming techniques include the concept of an object (encapsulation, and abstraction) but do not include the class-based models of inheritance.

History

The concepts of object-oriented programming first took root in Simula 67, a language designed for making simulations, created by Ole-Johan Dahl and Kristen Nygaard of the Norwegian Computing Centre in Oslo. (Reportedly, the story is that they were working on ship simulations, and were confounded by the combinatorial explosion of how the different attributes from different ships could affect one another. The idea occurred to group the different types of ships into different classes of objects, each class of objects being responsible for defining its own data and behavior.) They were later refined in Smalltalk, which was developed in Simula at Xerox PARC, but was designed to be a fully dynamic system in which objects could be created and modified "on the fly" rather than having a system based on static programs.

Object-oriented programming "took off" as the dominant programming methodology during the mid-1980s, largely due to the influence of C++, an extension of the C programming language. Its dominance was further cemented by the rising popularity of Graphical user interfaces, for which object-oriented programming is allegedly well-suited. Indeed, the rise of GUIs changed the user focus from the sequential instructions of text-based interfaces to the more dynamic manipulation of tangible components. An example of a closely related dynamic GUI library and OOP language can be found in the Cocoa frameworks on Mac OS X, written in Objective C, an object-oriented, dynamic messaging extension to C based on Smalltalk.

Object-oriented features were added to many existing languages during that time, including Ada, BASIC, Lisp, Pascal, and others. Adding these features to languages that were not initially designed for them often led to problems with compatibility and maintainability of code. "Pure" object-oriented languages, on the other hand, lacked features that many programmers had come to depend upon. To bridge this gap, many attempts have been made to create new languages based on object-oriented methods but allowing some procedural features in "safe" ways. Bertrand Meyer's Eiffel was an early and moderately successful language with those goals.

In the past decade Java has emerged in wide use partially because of it similarity to the C language but more importantly because if its implementation using a virtual machine that theoretically runs code unchanged on many different platforms, the latter of which makes it the darling of larger development shops with heterogeneous environments.

More recently, a number of languages have emerged that are primarily object-oriented yet compatible with procedural methodology, such as Python and Ruby. Besides Java, probably the most commercially important recent object-oriented languages are VB.NET and C Sharp designed for Microsoft's .NET platform.

Just as procedural programming led to refinements of technique such as structured programming, modern object-oriented software design methods include refinements such as the use of design patterns, design by contract, and modelling languages (such as UML).

Further reading

  • Booch, Grady. (1993) ISBN 0805353402 Object-Oriented Analysis and Design with Applications (Second Edition). Addison-Wesley.
  • Gamma, Erich, Richard Helm, Ralph Johnson, John Vlissides. (1995) ISBN 0201633612 Design Patterns: Elements of Reusable Object Oriented Software. Addison-Wesley.
  • Meyer, Bertrand. (1997) ISBN 0136291554 Object-Oriented Software Construction (Second Edition). Prentice Hall.
  • Rumbaugh, James, Michael Blaha, William Premerlani, Frederick Eddy, William Lorensen. (1991) ISBN 0136298419 Object-Oriented Modeling and Design. Prentice Hall.
  • Jacobsen, Ivar. (1994) ISBN 0201544350 Object-Oriented Software Engineering: A Use Case-Driven Approach. Addison-Wesley.
  • Abelson, Harold, Gerald Jay Sussman with Julie Sussman. (1996) ISBN 0262011530 Structure and Interpretation of Computer Programs (Second edition). The MIT Press

See also: