Object-oriented programming |
In computer science, object-oriented programming, OOP for short, is a computer programming paradigm.
The idea behind object-oriented programming is that a computer program is composed of a collection of individual units, or objects , as opposed to a traditional view in which a program is a list of instructions to the computer. Each object is capable of receiving messages, processing data, and sending messages to other objects.
Object-oriented programming is claimed to give more flexibility, easing changes to programs, and is widely popular in large scale software engineering. Furthermore, proponents of OOP claim that OOP is easier to learn for those new to computer programming than previous approaches, and that the OOP approach is often simpler to develop and to maintain, lending itself to more direct analysis, coding, and understanding of complex situations and procedures than other programming methods.
=Fundamental concepts=
Object-oriented programming emphasizes the following concepts:
=OOP as a new paradigm, point of view or marketing term=
OOP is subject to much contention as to its precise definition or its principal ideas.
In the most general terms, OOP is the practice of writing program text decomposed in modules that encapsulate the representation of one data type per module, instead of collections of functions that call each other, or clauses that trigger each other.
They have been brought together, with associated terminology, to create a programming framework. Together the ideas behind OO are said to be so powerful they create a paradigm shift in programming.
Other paradigms such as Functional_programming and procedural_programming programming focus primarily on the actions, and logical programming focuses on the logical assertions that trigger execution of program code.
OOP arose independently out of research into simulation system oriented languages, with SIMULA 67, and out of research into highly secure system architectures, with capability based OS and CPU architectures.
Some experts say that the original definition of Object-oriented came from the object (grammar) in grammar. The requirements for the software is always subject (grammar)-oriented and since the requirements for the subject is often complicated, monolithic complicated programs were created.
Some of the researchers at that time started thinking in an object (grammar)-oriented way, which was a paradigm shift from the usual subject-oriented thinking.
According to the object-oriented principles, the verb is attached to the object and logic associated to the requirement is handled in the object. The following are some examples of the ways by which a subject oriented requirement is translated into object oriented thinking:
One distinguishing feature of OOP is the handling of subtypes of data types.
Objects data are generally required to satisfy programmer-defined constraints (i.e. class (computer science)s). A datatype restricted with such constraint is a subtype of the same datatype without the constraint. These constraints are then both relied on and preserved by the actions (methods) defined for the data. These constraints may either be explicitly declared or implicitly assumed by the programmer. Object-oriented languages provide mechanisms for ensuring that such assumptions are local to one part of the program. They are usually part of Documentation of object-oriented programs.
OOP itself has been used to market many products and services and the actual definitions and benefits attributed to OOP have often been colored by commercial marketing goals. Similarly, many programming languages have a specific view to OOP that is less general in certain aspects from the more general definition.
Widely-used terminology distinguishes object-oriented programming from object-based . The former is held to include inheritance (described below), while the latter does not.
The exact definitions of these have some variation depending on point of view. In particular, languages with static typing often have slightly different views of OO than languages with dynamic typing, caused by focus on compile-time vs. run-time properties of the programs.
Notes: Abstraction is important to but not unique to OOP.
Reusability is the benefit most often claimed for OOP. However, that is sometimes disputed as being a large or primary benefit. The ability to maintain a program once written, the ability to do localized debugging, and the ability to do much larger parallel development efforts are all cited as more significant reasons to use an OOP language.
OOP is often called a paradigm rather than a 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.
The paradigm of OOP is essentially not that of programming but one of design. A system is designed by defining the objects that will exist in that system, the code which actually does the work is irrelevant to the object, or the people using the object, due to encapsulation. The challenge in OOP therefore is of designing a sane object system.
It should be noted that there are distinct parallels between the object-oriented paradigm and Systems theory. OOP focuses on objects as units in a system, whereas systems theory focuses on the system itself. In between, one may find software design patterns or other techniques that use classes and objects as building blocks for larger components. Such components can be seen as an intermediate step from the object-oriented paradigm towards the more real-life oriented models of systems theory.
==Actor model==
OOP is a decomposition paradigm for program code, not a model for computation.
OOP is often confused with the Actor model of computation. In response to a message that it receives, an Actor can make local decisions, create more Actors, send more messages, and determine how to respond to the next message received.
Almost all OOP languages and systems, including all the major ones such as Simula, Smalltalk, C plus plus, Java programming language, Python programming language and C sharp have message passing programming capabilities.
See Actor model implementation for a discussion on implementations of the Actor model.
In OOP the emphasis is not on how computation is organized, but on how program text is decomposed into modules, because it is this decomposition that matters as to the program text s comprehensibility and maintainability.
OOP is based on the assumption that the program text s comprehensibility and maintainability is improved by decomposing it into modules, and that the best way to decompose it into modules is to minimize dependencies among modules and the cohesion of functions inside the module, and that this is best achieved by encapsulating the representation of a data type in each module. ...
=Subparadigms=
There are several distinct styles of object-oriented programming. The distinctions between different styles occur because different programming languages emphasize different aspects of object-oriented facilities and combine with other constructs in different ways.
==OOP with procedural languages==
In procedural languages, OOP often appears as a form where data types are extended to behave like a type of an object in OOP, very similar to an abstract data type with an extension such as inheritance (computer science). Each method (computer science) is actually a subprogram which is syntactically bound to a class.
== Static typing with the object-oriented paradigm ==
Many object-oriented programming languages, such as C_plus_plus and Java_programming_language, have a static type system, that can be used to check and enforce constraints of object-oriented design to some degree. Object-oriented facilities combine with static typing in various ways. class (computer science)es are types of objects. Some object-oriented languages, such as Eiffel_programming_language, enforce invariant (computer science)s with the type system. Many object-oriented languages provide mechanisms for statically checking the type of method parameters, types of private and public data members, types of object references and check the correctness of inheritance and subtyping relationships. Static type checking can also check API compatibility, enforce data constraints on the users of libraries created with object-oriented methods and reduce the number of run-time type checks performed at run-time for various forms of method dispatch.
See Class-based OOP.
==Prototype-based models==
Other than using classes, prototyping is another, less popular, means of achieving object-oriented behavior sharing. After an object is defined, another similar object will be defined by referring to the original one as a template, then listing the new object s differences from the original. Perhaps the most popular prototype-based language is JavaScript, which is an implementation of ECMAScript; Self programming language, a programming language developed by Sun Microsystems is another instance of a language that uses prototyping for behavior sharing rather than classification. NewtonScript computer language, Act1, Io programming language and Delegation programming language are other examples. Hybrid and Exemplars use both prototyping and classification. In prototyping systems, objects themselves are the templates, while classification systems use classes as templates for objects.
The classification approach is so predominant in OOP that many people would define objects as encapsulations that share data by classification and inheritance. However, the more generic term behavior sharing acknowledges alternate techniques such as prototyping.
See Prototype-based_programming.
==Object-based model==
Object-based programming is centered around the creation of objects and their interactions, but may not have some of the key features of the class-based object-oriented paradigm such as inheritance. Such object-based systems are usually not regarded as object-oriented, because inheritance (viewing delegation (computer science) as a form of inheritance) is typically identified as the core feature of OOP.
==Multimethod model==
In this model, the receiver argument to a message is not given special status in message dispatch. Instead, the runtime values of all arguments to message are consulted to determine which method should be executed at runtime. This is related to double dispatch or multimethod dispatch.
Note that some feel that set theory or predicate logic is better suited to tackle this kind of complexity.
=Possible programming mistakes=
There are several common mistakes which programmers can commit in object oriented programming. For example, checking the type of an object instead of its membership is a common antipattern that counteracts the benefits of inheritance and polymorphism.
=Critique=
Hierarchical taxonomies often do not match the real world and real-world changes according to some critics, and should be avoided. However, many OOP proponents also suggest avoiding hierarchies and instead using OO techniques such as Object composition . A simple way of avoiding over-specification of hierarchies when modeling the real world is to consider the most specific types of objects and model relationships between those.
Also, many feel that OOP runs counter to the philosophy of relational modeling and relational databases, returning to the navigational database arrangements of the 1960s. It is not clear that this is the fault of OOP, since database modeling is based fundamentally on different premises than object-oriented modeling. In any case, relational database tables map to associations in object-oriented models, and the differences seem to be purely due to differences in focus. There is a history of misinterpretation of the relationship between object-oriented and relational modeling, which may muddy this issue. Also, there are variances in opinions about the roles and definitions of each. For example, some feel that OOP unnecessarily will copy noun relationship information from the database, when once and only once (no duplication) mantra dictates that such is bad practice. Others, in contrast, feel that OOP does not require this duplication, even though some existing OOP-to-relational database products mistakenly take this view, confusing object s data with relationship data. These people would also argue that strict distinctions should be made between data associated with the modelled objects, data associated with the roles and data associated with associations; in particular, object s data should not be (directly) stored in databases by this view, because databases are not a suitable storage for objects, the object already has some mechanism for storing its private information, and storage in database would require unnecessary replication between the object s image in its own storage and the database. The impedance mismatch between databases and OOP is caused by difference of scale between operations performed by objects and databases; database transactions, the smallest unit of work performed by databases, are much larger than any operations provided by OOP objects. Instead, by this view, databases are good for storing relationships between objects and the references to objects that are associated with roles that those relationships are built on; objects data could only be stored in databases after collecting and summarising data from groups of objects. Object s private representation details have no place in databases.
Needless to say, the proper relationship between OOP and databases is a complex and contentious topic which currently has no consensus solution.
While it is claimed that OOP is better for large applications , others feel that large applications should instead be reduced to many small applications, such as event-driven procedures that feed off of a database and declarative programming-based user interface frameworks.
The bottom line of the conflict seems to be that OOP is mostly a behaviorist view of software design which conflicts with the data-centric, declarative view. In the first, the interfaces are primarily behaviors, and data is grouped into objects. In the second the interfaces are primarily data (declarations) and behaviours are grouped into functions, such as tasks , or events . The tradeoffs of each approach are complex and often delve deep into human psychology theories. Sometimes both are used, such that OOP is used to build platform (computing) facilities and functional or declarative method is used to build applications for the platform.
Some feel that past criticisms leveled against procedural techniques are based upon poor languages, poor coding practices, or lack of knowledge about how to properly use databases instead of code to manage state and noun models .
It is recognized that OOP does not necessarily mean lack of complexity. Meta class programming for example is a demanding skill, and OOP programs can have a complex web of shared or distinct responsibilities, attributes and methods. It can be challenging to distribute responsibility over objects, or classes—one of many popular implementation schemes.
=Formal definition=
There have been several attempts on formalizing the concepts used in object-oriented programming. The following concepts and constructs have been used as interpretations of OOP concepts:
Attempts to find a consensus definition or theory behind objects have not proven very successful, and often diverge widely. For example, some definitions focus on mental activities, and some on mere program structuring. One of the simpler definitions is that OOP is the act of using map data structures or arrays that can contain functions and pointers to other maps, all with some syntactic and scoping sugar on top. Inheritance can be performed by cloning the maps (sometimes called prototyping ).
=OOP in scripting=
In recent years, object-based programming has become especially popular in scripting programming languages, with abstraction, Information hiding, Reusability, and ease of use being the most commonly cited reasons, (the value of Inheritance (computer science) in these languages is often questioned). Smalltalk is probably the first language that fits into this category. Python programming language and Ruby programming language are relatively recent languages that were built from the ground up with OOP in mind, while the popular Perl and PHP scripting languages have been slowly adding new object oriented features since versions 5 and 4, respectively. The ability of objects to represent real world entities is one reason for the popularity of JavaScript and ECMAScript, which is argued to be well suited to representing the Document Object Model of HTML and XML documents on the Internet.
See also: dynamic language
=History=
The concept of objects and instances in computing had its first major breakthrough with the PDP-1 system at MIT which was probably the earliest example of capability based architecture. Another early indication was Sketchpad made by Ivan Sutherland in 1963, however this was an application and not a programming paradigm.
The first object-oriented programming language was 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.)
The ideas in that language were then used in many other languages, from derivatives of Lisp programming language and Pascal programming language to the Smalltalk family of languages, which was developed 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 developed as the dominant programming methodology during the mid-1980s, largely due to the influence of C plus plus, 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. An example of a closely related dynamic GUI library and OOP language can be found in the Cocoa_(software) frameworks on Mac OS X, written in Objective C programming language, an object-oriented, dynamic messaging extension to C based on Smalltalk. OOP toolkits also enhanced the popularity of event-driven programming (although this concept is not limited to OOP).
At ETH Zürich, Niklaus Wirth and his colleagues had also been investigating such topics as data abstraction and modularity (programming). Modula-2 included both, and their succeeding design, Oberon programming language included a distinctive approach to object orientation, classes, and such. The approach is unlike Smalltalk, and very unlike C++.
Object-oriented features have been added to many existing languages during that time, including Ada programming language, BASIC programming language, Lisp programming language, Fortran, Pascal programming language, 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 programming language was an early and moderately successful language with those goals.
In the past decade Java programming language has emerged in wide use partially because of its similarity to C language and to C_plus_plus, but perhaps more importantly because of its implementation using a Java virtual machine that is intended to run code unchanged on many different platforms. This last feature has made it very attractive to larger development shops with heterogeneous environments. Microsoft s Microsoft .NET initiative has a similar objective and includes/supports several new languages, or variants of older ones.
More recently, a number of languages have emerged that are primarily object-oriented yet compatible with procedural methodology, such as Python programming language and Ruby programming language. Besides Java, probably the most commercially important recent object-oriented languages are Visual Basic .NET and C Sharp designed for Microsoft s Microsoft .NET platform.
Just as procedural programming led to refinements of techniques such as structured programming, modern object-oriented software design methods include refinements such as the use of design pattern (computer science), design by contract, and modeling languages (such as Unified Modeling Language).
=Learning=
In the past there have been many disputes as to the best Language to begin with when first learning Object Oriented programming. There are two different approaches most take when beginning object oriented programming. The first is the idea that it is best to start with a simpler language such as Java programming language, where the learner s focus on object-orientation is not distracted by complex language semantics. Still, others reason that it is best to start off with a more complicated language such as C_plus_plus, which more accurately supports all the structures and capabilities as prescribed by the Unified Modeling Language (UML). Note that there is no known language which inherently supports the full set of capabilities prescribed by UML.
=Languages=
Main article: Object-oriented programming language
*Ada programming language *C Sharp *C plus plus *Common Lisp Object System *Delphi programming language *Eiffel programming language *Fortran 2003 *JADE programming language *Java programming language *Modula-3 *Nice_programming_language *Oberon programming language *Objective-C *Objective Modula-2 *Objective Caml *Object Pascal *Perl *PHP *Python programming language *REALbasic *Ruby programming language *Simula *Sleep programming language *Smalltalk *Specman *SystemVerilog *UnrealScript *Visual Basic
=Further reading=
*Grady Booch: Object-Oriented Analysis and Design with Applications , Addison-Wesley, ISBN 0805353402 *Alan Kay: [http://gagne.homedns.org/%7etgagne/contrib/EarlyHistoryST.html The Early History of Smalltalk] *Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides: Design Patterns: Elements of Reusable Object Oriented Software , Addison-Wesley, ISBN 0201633612
=See also=
*Object-oriented programming language *Aspect-oriented programming *Programming paradigm *Software componentry *Interface description language *Distributed programming *List of object-oriented programming terms *Design pattern (computer science) *Refactoring *CORBA *Globus *DCOM *Glossary of object-oriented programming
=External links=
==Criticism==
|
|
