object-oriented programming
   HOME

TheInfoList



Object-oriented programming (OOP) is a
programming paradigm Programming paradigms are a way to classify programming languages based on their features. Languages can be classified into multiple paradigms. Some paradigms are concerned mainly with implications for the execution model of the language, such ...
based on the concept of " objects", which can contain
data Data (; ) are individual facts, statistics, or items of information, often numeric. In a more technical sense, data are a set of values of qualitative property, qualitative or quantity, quantitative variable (research), variables about one or m ...
and code: data in the form of
fields File:A NASA Delta IV Heavy rocket launches the Parker Solar Probe (29097299447).jpg, FIELDS heads into space in August 2018 as part of the ''Parker Solar Probe'' FIELDS is a science instrument on the ''Parker Solar Probe'' (PSP), designed to mea ...
(often known as
attributes Attribute may refer to: * Attribute (philosophy), an extrinsic property of an object * Attribute (research), a characteristic of an object * Grammatical modifier, in natural languages * Attribute (computing), a specification that defines a propert ...
or ''properties''), and code, in the form of procedures (often known as '' methods''). A feature of objects is that an object's own procedures can access and often modify the data fields of itself (objects have a notion of or ). In OOP, computer programs are designed by making them out of objects that interact with one another. OOP languages are diverse, but the most popular ones are class-based, meaning that objects are instances of
classes Class or The Class may refer to: Common uses not otherwise categorized * Class (biology), a taxonomic rank * Class (knowledge representation), a collection of individuals or objects * Class (philosophy), an analytical concept used differently f ...
, which also determine their
types Type may refer to: Science and technology Computing * Typing Typing is the process of writing or inputting text by pressing keys on a typewriter, computer keyboard, cell phone, or calculator. It can be distinguished from other means of text inpu ...
. Many of the most widely used programming languages (such as C++, Java, Python, etc.) are multi-paradigm and they support object-oriented programming to a greater or lesser degree, typically in combination with
imperative Imperative may refer to: *Imperative mood, a grammatical mood (or mode) expressing commands, direct requests, and prohibitions *Imperative programming, a programming paradigm in computer science *Imperative logic *Imperative (film), ''Imperative'' ...
,
procedural programming Procedural programming is a programming paradigm, derived from imperative programming In computer science, imperative programming is a programming paradigm that uses Statement (computer science), statements that change a program's state (comp ...
. Significant object-oriented languages include:
Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the islands of the Greater Sunda Islands in Indonesia Indonesia ( ), officially the Republic of Indonesia ( id, Republik Indonesia, links=yes ), is a country in Southeast Asia and Oceania ...
,
C++ C++ () is a general-purpose programming language In computer software, a general-purpose programming language is a programming language dedicated to a general-purpose, designed to be used for writing software in a wide variety of application ...
, C#,
Python PYTHON was a Cold War contingency plan of the Government of the United Kingdom, British Government for the continuity of government in the event of Nuclear warfare, nuclear war. Background Following the report of the Strath Committee in 1955, the ...
, R,
PHP PHP is a general-purpose scripting language especially suited to web development Web development is the work involved in developing a Web site A website (also written as web site) is a collection of web pages and related content that is ...

PHP
, Visual Basic.NET,
JavaScript JavaScript (), often abbreviated as JS, is a programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various kinds of Input/output, output. Programming lan ...

JavaScript
,
Ruby A ruby is a pink to blood-red coloured gemstone A gemstone (also called a gem, fine gem, jewel, precious stone, or semi-precious stone) is a piece of mineral crystal which, in cut and polished form, is used to make jewellery, jewelry or othe ...
,
Perl Perl is a family of two high-level, general-purpose, Interpreter (computing), interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the ...
,
SIMSCRIPT SIMSCRIPT is a free-form, English-like general-purpose simulation language conceived by Harry Markowitz Harry Max Markowitz (born August 24, 1927) is an American economist, and a recipient of the 1989 John von Neumann Theory Prize and the 1990 N ...
,
Object Pascal Object Pascal is an extension to the programming language Pascal that provides object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of "Object (computer science), objects", which can c ...
,
Objective-C Objective-C is a general-purpose, object-oriented programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various kinds of Input/output, output. Programmin ...
, Dart,
Swift The Society for Worldwide Interbank Financial Telecommunication (SWIFT), legally S.W.I.F.T. SCRL, provides a network that enables financial institutions worldwide to send and receive information about financial transactions in a secure, stan ...
, Scala, Kotlin,
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI The American National Standards Institute (ANSI ) is a private non-profit organization A nonprofit organization (NPO), also known as a non-business entity, ...
,
MATLAB MATLAB (an abbreviation of "matrix laboratory") is a Proprietary software, proprietary multi-paradigm programming language, multi-paradigm programming language and numerical analysis, numeric computing environment developed by MathWorks. MATLAB ...
, and
Smalltalk Smalltalk is an object-oriented Object-oriented programming (OOP) is a programming paradigm Program, programme, programmer, or programming may refer to: Business and management * Program management, the process of managing several rela ...

Smalltalk
.


History

Terminology invoking "objects" and "oriented" in the modern sense of object-oriented programming made its first appearance at
MIT Massachusetts Institute of Technology (MIT) is a private land-grant research university A research university is a university A university ( la, universitas, 'a whole') is an educational institution, institution of higher education, hi ...

MIT
in the late 1950s and early 1960s. In the environment of the
artificial intelligence Artificial intelligence (AI) is intelligence demonstrated by machines, unlike the natural intelligence human intelligence, displayed by humans and animal cognition, animals, which involves consciousness and emotionality. The distinction betwe ...

artificial intelligence
group, as early as 1960, "object" could refer to identified items (
LISP A lisp is a speech impairment in which a person misarticulates sibilant In phonetics Phonetics is a branch of linguistics that studies how humans produce and perceive sounds, or in the case of sign languages, the equivalent aspects of sign. P ...
atoms) with properties (attributes);
Alan Kay Alan Curtis Kay (born May 17, 1940) published by the Association for Computing Machinery The Association for Computing Machinery (ACM) is a US-based international learned society for computing. It was founded in 1947 and is the world's largest ...
later cited a detailed understanding of LISP internals as a strong influence on his thinking in 1966. Another early MIT example was
Sketchpad Sketchpad (a.k.a. Robot Draftsman) was a computer program written by Ivan Sutherland in 1963 in the course of his PhD thesis A thesis or dissertation (abbreviated diss.) is a document submitted in support of candidature for an academic deg ...
created by
Ivan Sutherland Ivan Edward Sutherland (born May 16, 1938) is an American computer scientist A computer scientist is a person A person (plural people or persons) is a being that has certain capacities or attributes such as reason, morality, consciousness o ...
in 1960–1961; in the glossary of the 1963 technical report based on his dissertation about Sketchpad, Sutherland defined notions of "object" and "instance" (with the class concept covered by "master" or "definition"), albeit specialized to graphical interaction. Also, an MIT
ALGOL ALGOL (; short for "Algorithmic Language") is a family of imperative Imperative may refer to: *Imperative mood, a grammatical mood (or mode) expressing commands, direct requests, and prohibitions *Imperative programming, a programming paradigm ...
version, AED-0, established a direct link between data structures ("plexes", in that dialect) and procedures, prefiguring what were later termed "messages", "methods", and "member functions". The Development of the Simula Languages,
Kristen Nygaard Kristen Nygaard (27 August 1926 – 10 August 2002) was a Norwegian computer scientist A computer scientist is a person A person (plural people or persons) is a being that has certain capacities or attributes such as reason, morality, con ...
,
Ole-Johan Dahl Ole-Johan Dahl (12 October 1931 – 29 June 2002) was a Norwegian computer scientist A computer scientist is a person A person (plural people or persons) is a being that has certain capacities or attributes such as reason, morality, conscio ...
, p.254
Uni-kl.ac.at
Simula Simula is the name of two simulation A simulation is the imitation of the operation of a real-world process or system over time. Simulations require the use of Conceptual model , models; the model represents the key characteristics or behav ...
introduced important concepts that are today an essential part of object-oriented programming, such as
class Class or The Class may refer to: Common uses not otherwise categorized * Class (biology), a taxonomic rank * Class (knowledge representation), a collection of individuals or objects * Class (philosophy), an analytical concept used differently f ...
and
object Object may refer to: General meanings * Object (philosophy), a thing, being, or concept ** Entity, something that is tangible and within the grasp of the senses ** Object (abstract), an object which does not exist at any particular time or pl ...
, inheritance, and
dynamic binding Dynamic binding may refer to: *Dynamic binding (computing), also known as late binding *Scope_(computer_science)#Dynamic_scoping, Dynamic scoping in programming languages *Dynamic binding (chemistry) See also

*Dynamic dispatch *Dynamic linking ...
. The object-oriented Simula programming language was used mainly by researchers involved with physical modelling, such as models to study and improve the movement of ships and their content through cargo ports. In the 1970s, the first version of the
Smalltalk Smalltalk is an object-oriented Object-oriented programming (OOP) is a programming paradigm Program, programme, programmer, or programming may refer to: Business and management * Program management, the process of managing several rela ...

Smalltalk
programming language was developed at
Xerox PARC PARC (Palo Alto Research Center; formerly Xerox PARC) is a research and development company in Palo Alto, California. Founded in 1969 by Jack Goldman, Jacob E. "Jack" Goldman, Xerox Corporation's chief scientist, the company was originally a divis ...
by
Alan Kay Alan Curtis Kay (born May 17, 1940) published by the Association for Computing Machinery The Association for Computing Machinery (ACM) is a US-based international learned society for computing. It was founded in 1947 and is the world's largest ...
,
Dan Ingalls Daniel Henry Holmes Ingalls Jr. (born 1944) is a pioneer of object-oriented computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perf ...

Dan Ingalls
and Adele Goldberg. Smalltalk-72 included a programming environment and was
dynamically typed In programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various kinds of Input/output, output. Programming languages are used in computer programming to i ...
, and at first was interpreted, not
compiled In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily ...

compiled
. Smalltalk became noted for its application of object orientation at the language-level and its graphical development environment. Smalltalk went through various versions and interest in the language grew. While Smalltalk was influenced by the ideas introduced in Simula 67 it was designed to be a fully dynamic system in which classes could be created and modified dynamically. In the 1970s, Smalltalk influenced the Lisp community to incorporate object-based techniques that were introduced to developers via the
Lisp machine Lisp machines are general-purpose computers designed to efficiently run Lisp A lisp is a speech impairment in which a person misarticulates sibilant In phonetics Phonetics is a branch of linguistics that studies how humans produce and per ...

Lisp machine
. Experimentation with various extensions to Lisp (such as LOOPS and
Flavors Flavor, or flavour, is the perceptual Perception (from the Latin Latin (, or , ) is a classical language belonging to the Italic languages, Italic branch of the Indo-European languages. Latin was originally spoken in the area arou ...
introducing
multiple inheritance Multiple inheritance is a feature of some object-oriented Object-oriented programming (OOP) is a programming paradigm Program, programme, programmer, or programming may refer to: Business and management * Program management, the process o ...

multiple inheritance
and mixins) eventually led to the Common Lisp Object System, which integrates functional programming and object-oriented programming and allows extension via a Meta-object protocol. In the 1980s, there were a few attempts to design processor architectures that included hardware support for objects in memory but these were not successful. Examples include the Intel iAPX 432 and the Linn Products, Linn Smart Rekursiv. In 1981, Goldberg edited the August issue of Byte Magazine, introducing Smalltalk and object-oriented programming to a wider audience. In 1986, the Association for Computing Machinery organised the first ''Conference on Object-Oriented Programming, Systems, Languages, and Applications'' (OOPSLA), which was unexpectedly attended by 1,000 people. In the mid-1980s
Objective-C Objective-C is a general-purpose, object-oriented programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various kinds of Input/output, output. Programmin ...
was developed by Brad Cox, who had used Smalltalk at ITT Inc., and Bjarne Stroustrup, who had used Simula for his PhD thesis, eventually went to create the object-oriented
C++ C++ () is a general-purpose programming language In computer software, a general-purpose programming language is a programming language dedicated to a general-purpose, designed to be used for writing software in a wide variety of application ...
. In 1985, Bertrand Meyer also produced the first design of the Eiffel (programming language), Eiffel language. Focused on software quality, Eiffel is a purely object-oriented programming language and a notation supporting the entire software lifecycle. Meyer described the Eiffel software development method, based on a small number of key ideas from software engineering and computer science, in Object-Oriented Software Construction. Essential to the quality focus of Eiffel is Meyer's reliability mechanism, Design by Contract, which is an integral part of both the method and language. In the early and mid-1990s object-oriented programming developed as the dominant programming paradigm when programming languages supporting the techniques became widely available. These included Visual FoxPro 3.0,
C++ C++ () is a general-purpose programming language In computer software, a general-purpose programming language is a programming language dedicated to a general-purpose, designed to be used for writing software in a wide variety of application ...
, and Delphi (programming language), Delphi. Its dominance was further enhanced by the rising popularity of graphical user interfaces, which rely heavily upon object-oriented programming techniques. An example of a closely related dynamic GUI library and OOP language can be found in the Cocoa (software), Cocoa frameworks on Mac OS X, written in
Objective-C Objective-C is a general-purpose, object-oriented programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various kinds of Input/output, output. Programmin ...
, 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), modular programming (although this had been in common use in the 1960s or earlier). Modula-2 (1978) included both, and their succeeding design, Oberon (programming language), Oberon, included a distinctive approach to object orientation, classes, and such. Object-oriented features have been added to many previously existing languages, including Ada (programming language), Ada, BASIC, Fortran, Pascal (programming language), Pascal, and COBOL. Adding these features to languages that were not initially designed for them often led to problems with compatibility and maintainability of code. More recently, a number of languages have emerged that are primarily object-oriented, but that are also compatible with procedural methodology. Two such languages are
Python PYTHON was a Cold War contingency plan of the Government of the United Kingdom, British Government for the continuity of government in the event of Nuclear warfare, nuclear war. Background Following the report of the Strath Committee in 1955, the ...
and Ruby programming language, Ruby. Probably the most commercially important recent object-oriented languages are
Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the islands of the Greater Sunda Islands in Indonesia Indonesia ( ), officially the Republic of Indonesia ( id, Republik Indonesia, links=yes ), is a country in Southeast Asia and Oceania ...
, developed by Sun Microsystems, as well as C# and Visual Basic.NET (VB.NET), both designed for Microsoft's .NET Framework, .NET platform. Each of these two frameworks shows, in its own way, the benefit of using OOP by creating an abstraction from implementation. VB.NET and C# support cross-language inheritance, allowing classes defined in one language to subclass classes defined in the other language.


Features

Object-oriented programming uses objects, but not all of the associated techniques and structures are supported directly in languages that claim to support OOP. It performs operations on operands. The features listed below are common among languages considered to be strongly class- and object-oriented (or multi-paradigm with OOP support), with notable exceptions mentioned.Deborah J. Armstrong. ''The Quarks of Object-Oriented Development''. A survey of nearly 40 years of computing literature which identified a number of fundamental concepts found in the large majority of definitions of OOP, in descending order of popularity: Inheritance, Object, Class, Encapsulation, Method, Message Passing, Polymorphism, and Abstraction., section 18.1 "What is Object-Oriented Programming?" Lists: Dynamic dispatch, encapsulation or multi-methods (multiple dispatch), subtype polymorphism, inheritance or delegation, open recursion ("this"/"self")


Shared with non-OOP languages

* Variable (computer science), Variables that can store information formatted in a small number of built-in data types like Integer (computer science), integers and alphanumeric Character (computing), characters. This may include data structures like String (computer science), strings, List (abstract data type), lists, and hash tables that are either built-in or result from combining variables using Pointer (computer programming), memory pointers. * Procedures – also known as functions, methods, routines, or subroutines – that take input, generate output, and manipulate data. Modern languages include structured programming constructs like Loop (computing), loops and Conditional (computer programming), conditionals. Modular programming support provides the ability to group procedures into files and modules for organizational purposes. Modules are namespaced so identifiers in one module will not conflict with a procedure or variable sharing the same name in another file or module.


Objects and classes

Languages that support object-oriented programming (OOP) typically use Inheritance (object-oriented programming), inheritance for code reuse and extensibility in the form of either Class-based programming, classes or Prototype-based programming, prototypes. Those that use classes support two main concepts: * Class (computer science), Classes – the definitions for the data format and available procedures for a given type or class of object; may also contain data and procedures (known as class methods) themselves, i.e. classes contain the data members and member functions * Object (computer science), Objects – instances of classes Objects sometimes correspond to things found in the real world. For example, a graphics program may have objects such as "circle", "square", "menu". An online shopping system might have objects such as "shopping cart", "customer", and "product". Sometimes objects represent more abstract entities, like an object that represents an open file, or an object that provides the service of translating measurements from U.S. customary to metric. Each object is said to be an instance (computer science), instance of a particular class (for example, an object with its name field set to "Mary" might be an instance of class Employee). Procedures in object-oriented programming are known as methods; variables are also known as
fields File:A NASA Delta IV Heavy rocket launches the Parker Solar Probe (29097299447).jpg, FIELDS heads into space in August 2018 as part of the ''Parker Solar Probe'' FIELDS is a science instrument on the ''Parker Solar Probe'' (PSP), designed to mea ...
, members, attributes, or properties. This leads to the following terms: * Class variables – belong to the ''class as a whole''; there is only one copy of each one * Instance variables or attributes – data that belongs to individual ''objects''; every object has its own copy of each one * Member variables – refers to both the class and instance variables that are defined by a particular class * Class methods – belong to the ''class as a whole'' and have access to only class variables and inputs from the procedure call * Instance methods – belong to ''individual objects'', and have access to instance variables for the specific object they are called on, inputs, and class variables Objects are accessed somewhat like variables with complex internal structure, and in many languages are effectively Pointer (computer programming), pointers, serving as actual references to a single instance of said object in memory within a heap or stack. They provide a layer of Abstraction (computer science), abstraction which can be used to separate internal from external code. External code can use an object by calling a specific instance method with a certain set of input parameters, read an instance variable, or write to an instance variable. Objects are created by calling a special type of method in the class known as a Constructor (object-oriented programming), constructor. A program may create many instances of the same class as it runs, which operate independently. This is an easy way for the same procedures to be used on different sets of data. Object-oriented programming that uses classes is sometimes called class-based programming, while prototype-based programming does not typically use classes. As a result, significantly different yet analogous terminology is used to define the concepts of ''object'' and ''instance''. In some languages classes and objects can be composed using other concepts like Trait (computer programming), traits and mixins.


Class-based vs prototype-based

In Class-based programming, class-based languages the ''classes'' are defined beforehand and the ''objects'' are instantiated based on the classes. If two objects ''apple'' and ''orange'' are instantiated from the class ''Fruit'', they are inherently fruits and it is guaranteed that you may handle them in the same way; e.g. a programmer can expect the existence of the same attributes such as ''color'' or ''sugar_content'' or ''is_ripe''. In Prototype-based programming, prototype-based languages the ''objects'' are the primary entities. No ''classes'' even exist. The ''prototype'' of an object is just another object to which the object is linked. Every object has one ''prototype'' link (and only one). New objects can be created based on already existing objects chosen as their prototype. You may call two different objects ''apple'' and ''orange'' a fruit, if the object ''fruit'' exists, and both ''apple'' and ''orange'' have ''fruit'' as their prototype. The idea of the ''fruit'' class doesn't exist explicitly, but as the equivalence class of the objects sharing the same prototype. The attributes and methods of the ''prototype'' are Delegation (object-oriented programming), delegated to all the objects of the equivalence class defined by this prototype. The attributes and methods ''owned'' individually by the object may not be shared by other objects of the same equivalence class; e.g. the attribute ''sugar_content'' may be unexpectedly not present in ''apple''. Only single inheritance can be implemented through the prototype.


Dynamic dispatch/message passing

It is the responsibility of the object, not any external code, to select the procedural code to execute in response to a method call, typically by looking up the method at run time in a table associated with the object. This feature is known as dynamic dispatch, and distinguishes an object from an abstract data type (or module), which has a fixed (static) implementation of the operations for all instances. If the call variability relies on more than the single type of the object on which it is called (i.e. at least one other parameter object is involved in the method choice), one speaks of multiple dispatch. A method call is also known as ''message passing''. It is conceptualized as a message (the name of the method and its input parameters) being passed to the object for dispatch.


Encapsulation

Encapsulation is an object-oriented programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse. Data encapsulation led to the important OOP concept of Information hiding, data hiding. If a class does not allow calling code to access internal object data and permits access through methods only, this is a strong form of abstraction or information hiding known as Encapsulation (object-oriented programming), encapsulation. Some languages (Java, for example) let classes enforce access restrictions explicitly, for example denoting internal data with the private keyword and designating methods intended for use by code outside the class with the public keyword. Methods may also be designed public, private, or intermediate levels such as protected (which allows access from the same class and its subclasses, but not objects of a different class). In other languages (like Python) this is enforced only by convention (for example, private methods may have names that start with an underscore). Encapsulation prevents external code from being concerned with the internal workings of an object. This facilitates code refactoring, for example allowing the author of the class to change how objects of that class represent their data internally without changing any external code (as long as "public" method calls work the same way). It also encourages programmers to put all the code that is concerned with a certain set of data in the same class, which organizes it for easy comprehension by other programmers. Encapsulation is a technique that encourages Coupling (computer programming), decoupling.


Composition, inheritance, and delegation

Objects can contain other objects in their instance variables; this is known as object composition. For example, an object in the Employee class might contain (either directly or through a pointer) an object in the Address class, in addition to its own instance variables like "first_name" and "position". Object composition is used to represent "has-a" relationships: every employee has an address, so every Employee object has access to a place to store an Address object (either directly embedded within itself, or at a separate location addressed via a pointer). Languages that support classes almost always support inheritance (object-oriented programming), inheritance. This allows classes to be arranged in a hierarchy that represents "is-a-type-of" relationships. For example, class Employee might inherit from class Person. All the data and methods available to the parent class also appear in the child class with the same names. For example, class Person might define variables "first_name" and "last_name" with method "make_full_name()". These will also be available in class Employee, which might add the variables "position" and "salary". This technique allows easy re-use of the same procedures and data definitions, in addition to potentially mirroring real-world relationships in an intuitive way. Rather than utilizing database tables and programming subroutines, the developer utilizes objects the user may be more familiar with: objects from their application domain. Subclasses can override the methods defined by superclasses. Multiple inheritance is allowed in some languages, though this can make resolving overrides complicated. Some languages have special support for mixins, though in any language with multiple inheritance, a mixin is simply a class that does not represent an is-a-type-of relationship. Mixins are typically used to add the same methods to multiple classes. For example, class UnicodeConversionMixin might provide a method unicode_to_ascii() when included in class FileReader and class WebPageScraper, which don't share a common parent. Abstract classes cannot be instantiated into objects; they exist only for the purpose of inheritance into other "concrete" classes that can be instantiated. In Java, the final (Java), final keyword can be used to prevent a class from being subclassed. The doctrine of composition over inheritance advocates implementing has-a relationships using composition instead of inheritance. For example, instead of inheriting from class Person, class Employee could give each Employee object an internal Person object, which it then has the opportunity to hide from external code even if class Person has many public attributes or methods. Some languages, like Go (programming language), Go do not support inheritance at all. The "open/closed principle" advocates that classes and functions "should be open for extension, but closed for modification". Delegation (object-oriented programming), Delegation is another language feature that can be used as an alternative to inheritance.


Polymorphism

Subtyping – a form of polymorphism (computer science), polymorphism – is when calling code can be agnostic as to which class in the supported hierarchy it is operating on – the parent class or one of its descendants. Meanwhile, the same operation name among objects in an inheritance hierarchy may behave differently. For example, objects of type Circle and Square are derived from a common class called Shape. The Draw function for each type of Shape implements what is necessary to draw itself while calling code can remain indifferent to the particular type of Shape being drawn. This is another type of abstraction that simplifies code external to the class hierarchy and enables strong separation of concerns.


Open recursion

In languages that support open recursion, object methods can call other methods on the same object (including themselves), typically using a special variable or keyword called this or self. This variable is ''name binding, late-bound''; it allows a method defined in one class to invoke another method that is defined later, in some subclass thereof.


OOP languages

Simula Simula is the name of two simulation A simulation is the imitation of the operation of a real-world process or system over time. Simulations require the use of Conceptual model , models; the model represents the key characteristics or behav ...
(1967) is generally accepted as being the first language with the primary features of an object-oriented language. It was created for making Computer simulation, simulation programs, in which what came to be called objects were the most important information representation.
Smalltalk Smalltalk is an object-oriented Object-oriented programming (OOP) is a programming paradigm Program, programme, programmer, or programming may refer to: Business and management * Program management, the process of managing several rela ...

Smalltalk
(1972 to 1980) is another early example, and the one with which much of the theory of OOP was developed. Concerning the degree of object orientation, the following distinctions can be made: * Languages called "pure" OO languages, because everything in them is treated consistently as an object, from primitives such as characters and punctuation, all the way up to whole classes, prototypes, blocks, modules, etc. They were designed specifically to facilitate, even enforce, OO methods. Examples:
Ruby A ruby is a pink to blood-red coloured gemstone A gemstone (also called a gem, fine gem, jewel, precious stone, or semi-precious stone) is a piece of mineral crystal which, in cut and polished form, is used to make jewellery, jewelry or othe ...
, Scala,
Smalltalk Smalltalk is an object-oriented Object-oriented programming (OOP) is a programming paradigm Program, programme, programmer, or programming may refer to: Business and management * Program management, the process of managing several rela ...

Smalltalk
, Eiffel (programming language), Eiffel, Emerald (programming language), Emerald, JADE (programming language), JADE, Self (programming language), Self, Raku (programming language), Raku. * Languages designed mainly for OO programming, but with some procedural elements. Examples:
Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the islands of the Greater Sunda Islands in Indonesia Indonesia ( ), officially the Republic of Indonesia ( id, Republik Indonesia, links=yes ), is a country in Southeast Asia and Oceania ...
,
Python PYTHON was a Cold War contingency plan of the Government of the United Kingdom, British Government for the continuity of government in the event of Nuclear warfare, nuclear war. Background Following the report of the Strath Committee in 1955, the ...
,
C++ C++ () is a general-purpose programming language In computer software, a general-purpose programming language is a programming language dedicated to a general-purpose, designed to be used for writing software in a wide variety of application ...
, C#, Delphi (programming language), Delphi/
Object Pascal Object Pascal is an extension to the programming language Pascal that provides object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of "Object (computer science), objects", which can c ...
, VB.NET. * Languages that are historically Procedural programming, procedural languages, but have been extended with some OO features. Examples:
PHP PHP is a general-purpose scripting language especially suited to web development Web development is the work involved in developing a Web site A website (also written as web site) is a collection of web pages and related content that is ...

PHP
,
Perl Perl is a family of two high-level, general-purpose, Interpreter (computing), interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the ...
, Visual Basic (derived from BASIC),
MATLAB MATLAB (an abbreviation of "matrix laboratory") is a Proprietary software, proprietary multi-paradigm programming language, multi-paradigm programming language and numerical analysis, numeric computing environment developed by MathWorks. MATLAB ...
, COBOL 2002, Fortran 2003, ABAP, Ada (programming language), Ada 95, Pascal (programming language), Pascal. * Languages with most of the features of objects (classes, methods, inheritance), but in a distinctly original form. Examples: Oberon (programming language), Oberon (Oberon-1 or Oberon-2). * Languages with abstract data type support which may be used to resemble OO programming, but without all features of object-orientation. This includes object-based, object-''based'' and Prototype-based programming, prototype-based languages. Examples:
JavaScript JavaScript (), often abbreviated as JS, is a programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various kinds of Input/output, output. Programming lan ...

JavaScript
, Lua (programming language), Lua, Modula-2, CLU (programming language), CLU. * Chameleon languages that support multiple paradigms, including OO. Tcl stands out among these for TclOO, a hybrid object system that supports both prototype-based programming and class-based OO.


OOP in dynamic languages

In recent years, object-oriented programming has become especially popular in dynamic programming languages.
Python PYTHON was a Cold War contingency plan of the Government of the United Kingdom, British Government for the continuity of government in the event of Nuclear warfare, nuclear war. Background Following the report of the Strath Committee in 1955, the ...
, Windows PowerShell, PowerShell,
Ruby A ruby is a pink to blood-red coloured gemstone A gemstone (also called a gem, fine gem, jewel, precious stone, or semi-precious stone) is a piece of mineral crystal which, in cut and polished form, is used to make jewellery, jewelry or othe ...
and Groovy (programming language), Groovy are dynamic languages built on OOP principles, while
Perl Perl is a family of two high-level, general-purpose, Interpreter (computing), interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the ...
and
PHP PHP is a general-purpose scripting language especially suited to web development Web development is the work involved in developing a Web site A website (also written as web site) is a collection of web pages and related content that is ...

PHP
have been adding object-oriented features since Perl 5 and PHP 4, and ColdFusion since version 6. The Document Object Model of HTML, XHTML, and XML documents on the Internet has bindings to the popular
JavaScript JavaScript (), often abbreviated as JS, is a programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various kinds of Input/output, output. Programming lan ...

JavaScript
/ECMAScript language. JavaScript is perhaps the best known prototype-based programming language, which employs cloning from prototypes rather than inheriting from a class (contrast to class-based programming). Another scripting language that takes this approach is Lua (programming language), Lua.


OOP in a network protocol

The messages that flow between computers to request services in a client-server environment can be designed as the linearizations of objects defined by class objects known to both the client and the server. For example, a simple linearized object would consist of a length field, a code point identifying the class, and a data value. A more complex example would be a command consisting of the length and code point of the command and values consisting of linearized objects representing the command's parameters. Each such command must be directed by the server to an object whose class (or superclass) recognizes the command and is able to provide the requested service. Clients and servers are best modeled as complex object-oriented structures. Distributed Data Management Architecture (DDM) took this approach and used class objects to define objects at four levels of a formal hierarchy: * Fields defining the data values that form messages, such as their length, code point and data values. * Objects and collections of objects similar to what would be found in a
Smalltalk Smalltalk is an object-oriented Object-oriented programming (OOP) is a programming paradigm Program, programme, programmer, or programming may refer to: Business and management * Program management, the process of managing several rela ...

Smalltalk
program for messages and parameters. * Managers similar to IBM i Object (IBM i), Objects, such as a directory to files and files consisting of metadata and records. Managers conceptually provide memory and processing resources for their contained objects. * A client or server consisting of all the managers necessary to implement a full processing environment, supporting such aspects as directory services, security and concurrency control. The initial version of DDM defined distributed file services. It was later extended to be the foundation of DRDA, Distributed Relational Database Architecture (DRDA).


Design patterns

Challenges of object-oriented design are addressed by several approaches. Most common is known as the Design Patterns (book), design patterns codified by Gamma ''et al.''. More broadly, the term "design pattern (computer science), design patterns" can be used to refer to any general, repeatable, solution pattern to a commonly occurring problem in software design. Some of these commonly occurring problems have implications and solutions particular to object-oriented development.


Inheritance and behavioral subtyping

It is intuitive to assume that inheritance creates a program semantics, semantic "is a" relationship, and thus to infer that objects instantiated from subclasses can always be ''safely'' used instead of those instantiated from the superclass. This intuition is unfortunately false in most OOP languages, in particular in all those that allow mutable objects. Subtype polymorphism as enforced by the type checker in OOP languages (with mutable objects) cannot guarantee behavioral subtyping in any context. Behavioral subtyping is undecidable in general, so it cannot be implemented by a program (compiler). Class or object hierarchies must be carefully designed, considering possible incorrect uses that cannot be detected syntactically. This issue is known as the Liskov substitution principle.


Gang of Four design patterns

''Design Patterns (book), Design Patterns: Elements of Reusable Object-Oriented Software'' is an influential book published in 1994 by Erich Gamma, Richard Helm, Ralph Johnson (computer scientist), Ralph Johnson, and John Vlissides, often referred to humorously as the "Gang of Four". Along with exploring the capabilities and pitfalls of object-oriented programming, it describes 23 common programming problems and patterns for solving them. As of April 2007, the book was in its 36th printing. The book describes the following patterns: * ''Creational patterns'' (5): Factory method pattern, Abstract factory pattern, Singleton pattern, Builder pattern, Prototype pattern * ''Structural patterns'' (7): Adapter pattern, Bridge pattern, Composite pattern, Decorator pattern, Facade pattern, Flyweight pattern, Proxy pattern * ''Behavioral patterns'' (11): Chain-of-responsibility pattern, Command pattern, Interpreter pattern, Iterator pattern, Mediator pattern, Memento pattern, Observer pattern, State pattern, Strategy pattern, Template method pattern, Visitor pattern


Object-orientation and databases

Both object-oriented programming and relational database management systems (RDBMSs) are extremely common in software . Since relational databases don't store objects directly (though some RDBMSs have object-oriented features to approximate this), there is a general need to bridge the two worlds. The problem of bridging object-oriented programming accesses and data patterns with relational databases is known as object-relational impedance mismatch. There are a number of approaches to cope with this problem, but no general solution without downsides. One of the most common approaches is object-relational mapping, as found in Integrated development environment, IDE languages such as Visual FoxPro and libraries such as Java Data Objects and Ruby on Rails' ActiveRecord. There are also object databases that can be used to replace RDBMSs, but these have not been as technically and commercially successful as RDBMSs.


Real-world modeling and relationships

OOP can be used to associate real-world objects and processes with digital counterparts. However, not everyone agrees that OOP facilitates direct real-world mapping (see object-oriented programming#Criticism, Criticism section) or that real-world mapping is even a worthy goal; Bertrand Meyer argues in ''Object-Oriented Software Construction''Meyer, Second Edition, p. 230 that a program is not a model of the world but a model of some part of the world; "Reality is a cousin twice removed". At the same time, some principal limitations of OOP have been noted. For example, the circle-ellipse problem is difficult to handle using OOP's concept of inheritance (object-oriented programming), inheritance. However, Niklaus Wirth (who popularized the adage now known as Wirth's law: "Software is getting slower more rapidly than hardware becomes faster") said of OOP in his paper, "Good Ideas through the Looking Glass", "This paradigm closely reflects the structure of systems 'in the real world', and it is therefore well suited to model complex systems with complex behaviours" (contrast KISS principle). Steve Yegge and others noted that natural languages lack the OOP approach of strictly prioritizing ''things'' (objects/nouns) before ''actions'' (methods/verbs). This problem may cause OOP to suffer more convoluted solutions than procedural programming.


OOP and control flow

OOP was developed to increase the code reuse, reusability and software maintenance, maintainability of source code. Transparent representation of the control flow had no priority and was meant to be handled by a compiler. With the increasing relevance of parallel hardware and thread (computer science), multithreaded coding, developing transparent control flow becomes more important, something hard to achieve with OOP.


Responsibility- vs. data-driven design

Responsibility-driven design defines classes in terms of a contract, that is, a class should be defined around a responsibility and the information that it shares. This is contrasted by Wirfs-Brock and Wilkerson with Data-driven programming, data-driven design, where classes are defined around the data-structures that must be held. The authors hold that responsibility-driven design is preferable.


SOLID and GRASP guidelines

SOLID (object-oriented design), SOLID is a mnemonic invented by Michael Feathers that stands for and advocates five programming practices: * Single responsibility principle * Open/closed principle * Liskov substitution principle * Interface segregation principle * Dependency inversion principle GRASP (object-oriented design), GRASP (General Responsibility Assignment Software Patterns) is another set of guidelines advocated by Craig Larman.


Criticism

The OOP paradigm has been criticised for a number of reasons, including not meeting its stated goals of reusability and modularity, and for overemphasizing one aspect of software design and modeling (data/objects) at the expense of other important aspects (computation/algorithms). Luca Cardelli has claimed that OOP code is "intrinsically less efficient" than procedural code, that OOP can take longer to compile, and that OOP languages have "extremely poor modularity properties with respect to class extension and modification", and tend to be extremely complex. The latter point is reiterated by Joe Armstrong (programming), Joe Armstrong, the principal inventor of Erlang (programming language), Erlang, who is quoted as saying:Armstrong, Joe. In ''Coders at Work: Reflections on the Craft of Programming.'' Peter Seibel, ed
Codersatwork.com
, Accessed 13 November 2009.
A study by Potok et al. has shown no significant difference in productivity between OOP and procedural approaches. Christopher J. Date stated that critical comparison of OOP to other technologies, relational in particular, is difficult because of lack of an agreed-upon and rigorous definition of OOP;C. J. Date, Introduction to Database Systems, 6th-ed., Page 650 however, Date and Darwen have proposed a theoretical foundation on OOP that uses OOP as a kind of customizable data type, type system to support RDBMS.C. J. Date, Hugh Darwen. ''Foundation for Future Database Systems: The Third Manifesto'' (2nd Edition) In an article Lawrence Krubner claimed that compared to other languages (LISP dialects, functional languages, etc.) OOP languages have no unique strengths, and inflict a heavy burden of unneeded complexity. Alexander Stepanov compares object orientation unfavourably to generic programming: Paul Graham (computer programmer), Paul Graham has suggested that OOP's popularity within large companies is due to "large (and frequently changing) groups of mediocre programmers". According to Graham, the discipline imposed by OOP prevents any one programmer from "doing too much damage". Leo Brodie has suggested a connection between the standalone nature of objects and a tendency to duplicate code in violation of the don't repeat yourself principle of software development. Steve Yegge noted that, as opposed to functional programming: Rich Hickey, creator of Clojure, described object systems as overly simplistic models of the real world. He emphasized the inability of OOP to model time properly, which is getting increasingly problematic as software systems become more concurrent.Rich Hickey, JVM Languages Summit 2009 keynote
Are We There Yet?
November 2009.
Eric S. Raymond, a Unix programmer and open-source software advocate, has been critical of claims that present object-oriented programming as the "One True Solution", and has written that object-oriented programming languages tend to encourage thickly layered programs that destroy transparency. Raymond compares this unfavourably to the approach taken with Unix and the C (programming language), C programming language. Rob Pike, a programmer involved in the creation of UTF-8 and Go (programming language), Go, has called object-oriented programming "the Roman numerals of computing" and has said that OOP languages frequently shift the focus from data structures and algorithms to
types Type may refer to: Science and technology Computing * Typing Typing is the process of writing or inputting text by pressing keys on a typewriter, computer keyboard, cell phone, or calculator. It can be distinguished from other means of text inpu ...
. Furthermore, he cites an instance of a
Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the islands of the Greater Sunda Islands in Indonesia Indonesia ( ), officially the Republic of Indonesia ( id, Republik Indonesia, links=yes ), is a country in Southeast Asia and Oceania ...
professor whose "idiomatic" solution to a problem was to create six new classes, rather than to simply use a lookup table.


Formal semantics

Objects are the run-time entities in an object-oriented system. They may represent a person, a place, a bank account, a table of data, or any item that the program has to handle. There have been several attempts at formalizing the concepts used in object-oriented programming. The following concepts and constructs have been used as interpretations of OOP concepts: * F-Coalgebra, co algebraic data types * abstract data types (which have existential types) allow the definition of module (programming), modules but these do not support dynamic dispatch * recursive types * encapsulated state * Inheritance (object-oriented programming), inheritance * Record (computer science), records are basis for understanding objects if function literals can be stored in fields (like in functional-programming languages), but the actual calculi need be considerably more complex to incorporate essential features of OOP. Several extensions of System F-sub, System F<: that deal with mutable objects have been studied; these allow both subtype polymorphism and parametric polymorphism (generics) Attempts to find a consensus definition or theory behind objects have not proven very successful (however, see Abadi & Cardelli
''A Theory of Objects''
ref name="AbadiCardelli">
for formal definitions of many OOP concepts and constructs), and often diverge widely. For example, some definitions focus on mental activities, and some on 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 sugar, syntactic and scoping sugar on top. Inheritance can be performed by cloning the maps (sometimes called "prototyping").


See also

* Comparison of programming languages (object-oriented programming) * Comparison of programming paradigms * Component-based software engineering * Design by contract * Object association * Object database * Object model reference * Object modeling language * Object-oriented analysis and design * Object-relational impedance mismatch (and The Third Manifesto) * Object-relational mapping


Systems

* CADES * Common Object Request Broker Architecture (CORBA) * Distributed Component Object Model * Distributed Data Management Architecture * Jeroo


Modeling languages

* IDEF4 * Interface description language * Lepus3 * Unified Modeling Language, UML


References


Further reading

* * * * * * * * * * * * * * * * *


External links


Introduction to Object Oriented Programming Concepts (OOP) and More
by L.W.C. Nirosh
Discussion on Cons of OOP


{{DEFAULTSORT:Object-Oriented Programming Object-oriented programming, Programming paradigms Norwegian inventions