Content deleted Content added
Stevebroshar (talk | contribs) →Object patterns: separate out the anti-pattern |
m unpiped links using script |
||
Line 2:
{{Redirect|Object-oriented|other meanings of object-oriented|Object-orientation (disambiguation){{!}}Object-orientation}}
{{Use dmy dates|date=January 2020}}
[[File:oop-uml-class-example.png|frame|right|[[
'''Object-oriented programming''' ('''OOP''') is a [[programming paradigm]] based on the concept of ''[[Object (computer science)|objects]]'',<ref name=alanKayOnOO /> which can contain [[data]] and [[source-code|code]]: data in the form of [[Field (computer science)|fields]] (often known as [[Attribute (computing)|attributes]] or [[Property (programming)|properties]]), and code in the form of [[Procedure (computer science)|procedures]] (often known as [[method (computing)|methods]]). In OOP, [[computer program]]s are designed by making them out of objects that interact with one another.<ref>{{Cite journal
Line 14:
}}</ref><ref>{{Cite book|last1=Lewis|first1=John|last2=Loftus|first2= William|title=Java Software Solutions Foundations of Programming Design 6th ed|publisher=Pearson Education Inc.|year=2008|isbn=978-0-321-53205-3}}, section 1.6 "Object-Oriented Programming"</ref>
Many of the most widely used programming languages (such as [[C++]], [[Java (programming language)|Java]],{{sfn|Bloch|2018|loc=Foreword|pp=xi-xii}} [[Python (programming language)|Python]], etc.) are [[
Significant object-oriented languages include [[Ada (programming language)|Ada]], [[ActionScript]], [[C++]], [[Common Lisp]], [[C Sharp (programming language)|C#]], [[Dart (programming language)|Dart]], [[Eiffel (programming language)|Eiffel]], [[Fortran|Fortran 2003]], [[Haxe]], [[Java (programming language)|Java]],{{sfn|Bloch|2018|loc=Foreword|pp=xi-xii}} [[Kotlin (programming language)|Kotlin]], [[Logo (programming language)|Logo]], [[MATLAB]], [[Objective-C]], [[Object Pascal]], [[Perl]], [[PHP]], [[Python (programming language)|Python]], [[R (programming language)|R]], [[Raku (programming language)|Raku]], [[Ruby (programming language)|Ruby]], [[Scala (programming language)|Scala]], [[SIMSCRIPT]], [[Simula]], [[Smalltalk]], [[Swift (programming language)|Swift]], [[Vala (programming language)|Vala]] and [[Visual Basic.NET]].
Line 20:
==History==
Terminology invoking "objects" in the modern sense of object-oriented programming made its first appearance at the [[artificial intelligence]] group at [[MIT]] in the late 1950s and early 1960s. "Object" referred to [[
|url = https://archive.org/details/lisp15programmer00john/page/105
|title = LISP 1.5 Programmer's Manual
Line 43:
}}</ref>
Another early MIT example was [[Sketchpad]] created by [[Ivan Sutherland]] 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.<ref>{{cite conference
|author=[[
|title=Sketchpad: a man-machine graphical communication system
|conference=AFIPS '63 (Spring): Proceedings of the May 21–23, 1963 Spring Joint Computer Conference
Line 72:
|access-date =13 May 2010 }}
</ref>
Topics such as [[data abstraction]] and [[
Independently of later MIT work such as AED, [[Simula]] was developed during the years 1961–1967.<ref name=simuladev/>
Line 88:
A 1976 MIT memo co-authored by [[Barbara Liskov]] lists [[Simula 67]], [[CLU (programming language)|CLU]], and [[Alphard (programming language)|Alphard]] as object-oriented languages, but does not mention Smalltalk.<ref>{{cite tech report |last=Jones |first=Anita K. |last2=Liskov|first2=Barbara H. |date=April 1976 |title=An Access Control Facility for Programming Languages |institution=MIT |number=CSG Memo 137|url=http://csg.csail.mit.edu/CSGArchives/memos/Memo-137.pdf }}</ref>
In the 1970s, the first version of the [[Smalltalk]] programming language was developed at [[Xerox PARC]] by [[Alan Kay]], [[Dan Ingalls]] and [[Adele Goldberg (computer scientist)|Adele Goldberg]]. Smalltalk-72 included a programming environment and was [[
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.<ref name="Bertrand Meyer 2009 329">{{Cite book|title=Touch of Class: Learning to Program Well with Objects and Contracts|author=Bertrand Meyer|publisher=Springer Science & Business Media|year=2009|isbn=978-3-540-92144-8|pages=329|bibcode=2009tclp.book.....M}}</ref>
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.<ref>{{cite journal
Line 105:
During the late 1970s and 1980s, object-oriented programming rose to prominence. The [[Flavors (programming language)|Flavors]] object-oriented Lisp was developed starting 1979, introducing [[multiple inheritance]] and [[mixins]].<ref>{{cite conference |last1=Moon |first1=David A. |author-link1=David A. Moon |date=June 1986 |title=Object-Oriented Programming with Flavors |book-title=Conference proceedings on Object-oriented Programming Systems Languages and Applications |pages=1–8 |isbn=978-0-89791-204-4 |conference=[[OOPSLA]] '86 |doi=10.1145/28697.28698 |s2cid=17150741 |url=https://www.cs.tufts.edu/comp/150FP/archive/david-moon/flavors.pdf |access-date=2022-03-17}}</ref> In 1981, Goldberg edited the August issue of [[Byte Magazine]], introducing Smalltalk and object-oriented programming to a wide audience.<ref>{{cite news |title=Introducing the Smalltalk Zoo |url=https://computerhistory.org/blog/introducing-the-smalltalk-zoo-48-years-of-smalltalk-history-at-chm/ |work=CHM |date=17 December 2020 |language=en}}</ref> LOOPS, the object system for [[Interlisp]]-D, was influenced by Smalltalk and Flavors, and a paper about it was published in 1982.<ref>{{cite conference | title=LOOPS: data and object oriented Programming for Interlisp|date=1982|conference=European AI Conference|last1=Bobrow|first1=D. G.|last2=Stefik|first2=M. J|url=https://www.markstefik.com/wp-content/uploads/2011/04/1982-Bobrow-Stefik-Data-Object-Pgming.pdf}}</ref> In 1986, the [[Association for Computing Machinery]] organized the first ''Conference on Object-Oriented Programming, Systems, Languages, and Applications'' (OOPSLA), which was attended by 1,000 people. Among other developments was 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 the mid-1980s [[Objective-C]] was developed by [[Brad Cox]], who had used Smalltalk at [[ITT Inc.]]. [[Bjarne Stroustrup]], who had used Simula for his PhD thesis, created the object-oriented [[C++]].<ref name="Bertrand Meyer 2009 329"/> In 1985, [[Bertrand Meyer]] also produced the first design of the [[
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,<ref>1995 (June) Visual [[FoxPro]] 3.0, FoxPro evolves from a procedural language to an object-oriented language. Visual FoxPro 3.0 introduces a database container, seamless client/server capabilities, support for ActiveX technologies, and OLE Automation and null support. [http://www.foxprohistory.org/foxprotimeline.htm#summary_of_fox_releases Summary of Fox releases]</ref><ref>FoxPro History web site: [http://www.foxprohistory.org/tableofcontents.htm Foxprohistory.org]</ref><ref>1995 Reviewers Guide to Visual FoxPro 3.0: [http://www.dfpug.de/loseblattsammlung/migration/whitepapers/vfp_rg.htm DFpug.de]</ref> [[C++]],<ref>{{Cite book|url=https://books.google.com/books?id=MHmqfSBTXsAC&pg=PA16|title=Object Oriented Programming with C++, 1E|isbn=978-81-259-2532-3|last1=Khurana|first1=Rohit|date=1 November 2009|publisher=Vikas Publishing House Pvt Limited }}</ref> and [[Delphi (programming language)|Delphi]]{{Citation needed|date=February 2010}}. Its dominance was further enhanced by the rising popularity of [[graphical user interface]]s, 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]], 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).
Line 179:
===Data abstraction and encapsulation===
Data [[Abstraction (computer science)|abstraction]] is a design pattern in which data are visible only to semantically related functions, to prevent misuse. The success of data abstraction leads to frequent incorporation of [[
In object oriented programming, objects provide a layer which can be used to separate internal from external code and implement abstraction and encapsulation. External code can only use an object by calling a specific instance method with a certain set of input parameters, reading an instance variable, or writing to an instance variable. A program may create many instances of objects as it runs, which operate independently. This technique, it is claimed, allows easy re-use of the same procedures and data definitions for different sets of data, in addition to potentially mirroring real-world relationships intuitively. Rather than utilizing database tables and programming subroutines, the developer utilizes objects the user may be more familiar with: objects from their application ___domain.<ref>{{cite book|last=Jacobsen|first=Ivar|title=Object Oriented Software Engineering|year=1992|publisher=Addison-Wesley ACM Press|isbn=978-0-201-54435-0|pages=[https://archive.org/details/objectorientedso00jaco/page/43 43–69]|author2=Magnus Christerson|author3=Patrik Jonsson|author4=Gunnar Overgaard|url=https://archive.org/details/objectorientedso00jaco/page/43}}</ref> These claims that the OOP paradigm enhances reusability and modularity have been criticized.<ref name="badprop"/><ref name="armstrongjoe"/>
Line 185:
If a class does not allow calling code to access internal object data and permits access through methods only, this is also a form of information hiding. Some languages (Java, for example) let classes enforce access restrictions explicitly, for example, denoting internal data with the <code>private</code> keyword and designating methods intended for use by code outside the class with the <code>public</code> keyword.{{sfn|Bloch|2018|loc=Chapter §4 Item15 Minimize the accessibility of classes and members|pp=73-77}} Methods may also be designed public, private, or intermediate levels such as <code>protected</code> (which allows access from the same class and its subclasses, but not objects of a different class).{{sfn|Bloch|2018|loc=Chapter §4 Item15 Minimize the accessibility of classes and members|pp=73-77}} In other languages (like Python) this is enforced only by convention (for example, <code>private</code> methods may have names that start with an [[underscore]]). In C#, Swift & Kotlin languages, <code>internal</code> keyword permits access only to files present in the same assembly, package, or module as that of the class.<ref>{{Cite web |date=2023-01-05 |title=What is Object Oriented Programming (OOP) In Simple Words? – Software Geek Bytes |url=https://softwaregeekbytes.com/object-oriented-programming-simple-words/ |access-date=2023-01-17 |language=en-US}}</ref>
In programming languages, particularly object-oriented ones, the emphasis on abstraction is vital. Object-oriented languages extend the notion of type to incorporate data abstraction, highlighting the significance of restricting access to internal data through methods.<ref>{{Cite journal |last1=Cardelli |first1=Luca |last2=Wegner |first2=Peter |date=1985-12-10 |title=On understanding types, data abstraction, and polymorphism |journal=ACM Computing Surveys |language=en |volume=17 |issue=4 |pages=471–523 |doi=10.1145/6041.6042 |issn=0360-0300|doi-access=free }}</ref> [[Eric S. Raymond]] has written that object-oriented programming languages tend to encourage thickly layered programs that destroy transparency.<ref name="Eric S. Raymond 2003">{{cite web|url=http://www.catb.org/esr/writings/taoup/html/unix_and_oo.html|title=The Art of Unix Programming: Unix and Object-Oriented Languages|author=Eric S. Raymond|date=2003|access-date=6 August 2014}}</ref> Raymond compares this unfavourably to the approach taken with Unix and the [[
The "[[open/closed principle]]" advocates that classes and functions "should be open for extension, but closed for modification". [[Luca Cardelli]] has claimed that OOP languages have "extremely poor modularity properties with respect to class extension and modification", and tend to be extremely complex.<ref name="badprop"/> The latter point is reiterated by [[Joe Armstrong (programming)|Joe Armstrong]], the principal inventor of [[Erlang (programming language)|Erlang]], who is quoted as saying:<ref name="armstrongjoe">Armstrong, Joe. In ''Coders at Work: Reflections on the Craft of Programming.'' Peter Seibel, ed. [http://www.codersatwork.com/ Codersatwork.com] {{Webarchive|url=https://web.archive.org/web/20100305165150/http://www.codersatwork.com/ |date=5 March 2010 }}, Accessed 13 November 2009.</ref>
Line 201:
===Open recursion===
A common feature of objects is that methods are attached to them and can access and modify the object's data fields. In this brand of OOP, there is usually a special name such as [[this (computer programming)|{{code|this|C++}}]] or {{code|self|swift}} used to refer to the current object. In languages that support [[open recursion]], object methods can call other methods on the same object (including themselves) using this name. This variable is ''[[
=={{Anchor|Object-oriented source code}}OOP languages==
Line 211:
* 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 (programming language)|Ruby]], [[Scala (programming language)|Scala]], [[Smalltalk]], [[Eiffel (programming language)|Eiffel]], [[Emerald (programming language)|Emerald]],<ref>{{cite web|url=http://www.emeraldprogramminglanguage.org/|title=The Emerald Programming Language| date=26 February 2011}}</ref> [[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 (programming language)|Java]], [[Python (programming language)|Python]], [[C++]], [[C Sharp (programming language)|C#]], [[Delphi (programming language)|Delphi]]/[[Object Pascal]], [[VB.NET]].
* Languages that are historically [[Procedural programming|procedural languages]], but have been extended with some OO features. Examples: [[PHP]], [[JavaScript]], [[Perl]], [[Visual Basic]] (derived from BASIC), [[MATLAB]], [[COBOL 2002]], [[Fortran 2003]], [[ABAP]], [[
* 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 [[
* 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.
Line 223:
===OOP in dynamic languages===
In recent years, object-oriented programming has become especially popular in [[dynamic programming language]]s. [[Python (programming language)|Python]], [[
The [[Document Object Model]] of [[HTML]], [[XHTML]], and [[XML]] documents on the Internet has bindings to the popular [[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]].
Line 250:
*[[First-class object]]: can be used without restriction
*[[
*[[Factory object]]: creates other objects
Line 270:
===Gang of Four design patterns===
{{Main|Design pattern (computer science)}}
''[[
The book describes the following patterns:
Line 311:
===SOLID and GRASP guidelines===
[[
* [[Single responsibility principle]]
* [[Open/closed principle]]
Line 359:
* [[Interface description language]]
* [[Lepus3]]
* [[
==References==
|