Object (computer science): Difference between revisions
Added new Objects and the Semantic Web section, and added Reference Section, also added Software Development namespace |
Stevebroshar (talk | contribs) link to OOAD |
||
(489 intermediate revisions by more than 100 users not shown) | |||
Line 1: | Line 1: | ||
{{Short description|Software abstraction with state, behavior, and identity}} |
|||
{{Software development process}} |
|||
In its simplest embodiment, an ''object'' is an allocated region of storage. Since programming languages use [[variable#Computer_programming|variable]]s to access objects, the terms ''object'' and ''variable'' are often used interchangeably. However, until memory is allocated, an object does not exist. |
|||
In [[software development]], an '''object''' is an [[entity]] that has [[State (computer science)|state]], [[behavior]], and [[Identity (object-oriented programming)|identity]].<ref name="ooa">{{cite book|title=Object-Oriented Analysis and Design with Applications |edition=3 |date=April 30, 2007 |author1=Grady Booch |author2=Robert Maksimchuk |author3=Michael Engle |author4=Bobbi Young |author5=Jim Conallen |author6=Kelli Houston |isbn=020189551X |publisher= Addison-Wesley Professional}}</ref>{{rp|78}} An object can [[model]] some part of [[reality]] or can be an [[invention]] of the [[design process]] whose collaborations with other such objects serve as the mechanisms that provide some higher-level behavior. Put another way, an object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the problem domain.<ref name="ooa"></ref>{{rp|76}} |
|||
In [[procedural programming]], an object may contain data or instructions, but not both. (Instructions may take the form of a procedure or function.) In [[object-oriented programming]], an object is an instance (or instantiation) of a [[class (computer science)|class]]. The class object contains a combination of data and the instructions that operate on that data, making the object capable of receiving [[message (computer science)|messages]], processing data, and sending messages to other objects. |
|||
A [[programming language]] can be classified based on its support for objects. A language that provides an encapsulation construct for state, behavior, and identity is classified as [[object-based language|object-based]]. If the language also provides [[polymorphism (computer science)|polymorphism]] and [[inheritance (object-oriented programming)|inheritance]] it is classified as [[Object-oriented programming|object-oriented]]. A language that supports creating an object from a [[class (computer science)|class]] is classified as [[class-based programming|class-based]]. A language that supports object creation via a template object is classified as [[prototype-based programming|prototype-based]]. |
|||
To give a real world analogy, if a person wanted to live in a house, neither a [[blueprint]] for a house, a photo of it, nor a scale model would be of any use. What is needed is a real house constructed according to specifications. In this analogy, the blueprint represents a class, and the real house represents the object. |
|||
The concept of object is used in many different software contexts, including: |
|||
== Theory == |
|||
* Possibly the most common use is [[Computer memory|in-memory]] objects in a [[computer program]] written in an object-based language. |
|||
In strictly [[mathematical]] branches of [[computer science]] the term '''object''' is used in a purely mathematical sense to refer to any "thing". While this interpretation is useful in the discussion of abstract theory, it is not concrete enough to serve as a [[Primitive type|primitive]] [[datatype]] in the discussion of more concrete branches (such as [[programming]]) that are closer to actual computation and [[information processing]]. Therefore, objects are still '''conceptual entities''', but generally correspond directly to a contiguous block of [[computer memory]] of a specific size at a specific location. This is because computation and information processing ultimately require a form of computer memory. Objects in this sense are fundamental primitives needed to accurately define concepts such as [[reference (computer science)|reference]]s, [[variable]]s, and [[name binding]]. This is why the rest of this article will focus on the concrete interpretation of ''object'' rather than the abstract one – object oriented programming. |
|||
* [[Information systems]] can be [[object-oriented analysis and design|modeled]] with objects representing their components and interfaces.<ref name="ooa"/>{{rp|39}} |
|||
Note that although a block of computer memory can appear contiguous on one level of [[Abstraction (computer science)|abstraction]] and incontiguous on another, the important thing is that it appears contiguous to the program that treats it as an object. That is, an object's private implementation details must not be exposed to clients of the object, and they must be able to change without requiring changes to client code. In particular, the size of the block of memory that forms the object must be able to change without changes to client code. |
|||
* In the [[relational model]] of [[database]] management, aspects such as [[Table (database)|table]] and [[Column (database)|column]] may act as objects.<ref name=Oppel>{{cite book |first=Andy |last=Oppel |title=SQL Demystified |publisher=McGraw Hill |year=2005| page=7 |isbn=0-07-226224-9}}</ref> |
|||
* [[Distributed object|Objects]] of a [[distributed computing]] system tend to be larger grained, longer lasting, and more service-oriented than programming objects. |
|||
Objects exist only within contexts that are aware of them; a piece of computer memory only holds an object if a program treats it as such (for example by reserving it for exclusive use by specific procedures and/or associating a [[data type]] with it). Thus, the [[object lifetime|lifetime of an object]] is the time during which it is treated as an object. This is why they are still conceptual entities, despite their physical presence in computer memory. |
|||
==See also== |
|||
In other words, abstract concepts that do not occupy memory space at runtime are, according to the definition, not objects; e.g., [[Design pattern (computer science)|design patterns]] exhibited by a set of classes, [[data type]]s in statically typed programs. |
|||
*{{annotated link|Actor model}} |
|||
*{{annotated link|Business object}} |
|||
*{{annotated link|Object lifetime}} |
|||
*{{annotated link|Object copying}} |
|||
*{{annotated link|Semantic Web}} |
|||
==References== |
|||
== Objects in object-oriented programming == |
|||
{{Reflist}} |
|||
In [[object-oriented programming]] (OOP), an instance of a program (i.e. a program running in a computer) is treated as a dynamic set of interacting objects. Objects in OOP extend the more general notion of objects described above to include a very specific kind of [[datatype|typing]], which among other things allows for: |
|||
# data members that represent the data associated with the object. |
|||
# [[method (computer science)|method]]s that access the data members in predefined ways. |
|||
In the case of most objects, the data members can only be accessed through the methods, making it easy to guarantee that the data will always remain in a well-defined state ([[class invariant]]s will be enforced). Some languages do not make distinctions between data members and methods. |
|||
In almost all object-oriented programming languages, a dot(.) operator is used to call a particular method/function of an object. For example, consider an arithmetic class named Arith_Class. This class contains functions like add(), subtract(), multiply() and divide(), that process results for two numbers sent to them. This class could be used to find the product of 78 and 69 by first of all creating an object of the class and then invoking its multiply method, as follows: |
|||
1 int result = 0; ''// Initialization'' |
|||
2 arith_Obj1 = new Arith_Class(); ''// Creating a new instance of Arith_Class'' |
|||
3 result = arith_Obj1.multiply(78,69); ''// Product of 78 and 69 stored in result variable |
|||
In a language where each object is created from a class, an object is called an '''instance''' of that class. If each object has a type, two objects with the same class would have the same [[datatype]]. Creating an instance of a class is sometimes referred to as '''instantiating''' the class. |
|||
A real-world example of an object would be "my dog", which is an instance of a [[Datatype|type]] (a [[Class (computer science)|class]]) called "dog", which is a [[Subclass (computer science)|subclass]] of a class "animal". In the case of a [[Polymorphism (computer science)|polymorphic]] object, some details of its type can be selectively ignored, for example a "dog" object could be used by a function looking for an "animal". So could a "cat", because it too belongs to the class of "animal". While being accessed as an "animal", some member attributes of a "dog" or "cat" would remain unavailable, such as the "tail" attribute, because not all animals have tails. |
|||
A ghost is an object that is [[Reference (computer science)|unreferenced]] in a [[Computer program|program]], and can therefore serve no purpose. In a garbage-collected language, the [[Garbage collection (computer science)|garbage collector]] would mark the memory occupied by the object as free, although it would still contain the object's data until it was overwritten. |
|||
Three properties characterize objects: |
|||
# [[Identity (object-oriented programming)|Identity]]: the property of an object that distinguishes it from other objects |
|||
# State: describes the data stored in the object |
|||
# Behavior: describes the methods in the object's [[Interface (computer science)|interface]] by which the object can be used |
|||
Some terms for specialized kinds of objects include: |
|||
*[[Singleton pattern|Singleton]] object: An object that is the only instance of its class during the lifetime of the program. |
|||
*Functor ([[function object]]): an object with a single method (in C++, this method would be the function operator, "operator()") that acts much like a function (like a C/C++ pointer to a function). |
|||
*[[Immutable object]]: an object set up with a fixed state at creation time and which does not vary afterward. |
|||
*[[First-class object]]: an object that can be used without restriction. |
|||
*[[Container (data structure)|Container]]: an object that can contain other objects. |
|||
*[[Factory object]]: an object whose purpose is to create other objects. |
|||
*[[Metaobject]]: an object from which other objects can be created (Compare with [[class (computer science)|class]], which is not necessarily an object) |
|||
*[[Prototype (computer science)|Prototype]]: a specialized metaobject from which other objects can be created by copying |
|||
*[[God object]]: an object that knows ''too much'' or does ''too much''. The God object is an example of an [[anti-pattern]]. |
|||
*[[Antiobjects]]: a computational metaphor useful to conceptualize and solve hard problems often with massively parallel approaches by swapping computational foreground and background. |
|||
*[[Filter object]] |
|||
== Objects and the Semantic Web == |
|||
The [[Semantic Web]] can be seen as a distributed data objects framework, and therefore can be validly seen as an Object Oriented Framework <ref>{{cite web|url=http://www.w3.org/2001/sw/BestPractices/SE/ODSD/|title=A Semantic Web Primer for Object-Oriented Software Developers|last1=Knublauch|first1=Holger|last2=Oberle|first2=Daniel|last3=Tetlow|first3=Phil|last4=Wallace|last4=Evan|publisher=[[W3C]]|date=2006-03-09|accessdate=2008-07-30}}</ref> <ref>{{cite web|url=http://www.w3.org/Architecture/NOTE-ioh-arch|title=An Evaluation of the World Wide Web with respect to Engelbart's Requirements|last=Connolly|first=Daniel|publisher=[[W3C]] |date=2002-08-13|accessdate=2008-07-30 }}</ref>. It is also quite valid to use a UML diagram to express a Semantic Web graph. |
|||
Both the Semantic Web and Object Oriented Programming have: |
|||
* Classes |
|||
* Attributes (also known as Relationships) |
|||
* Instances |
|||
Furthering this, [[Linked Data]] also introduces [[Dereferenceable Unified Resource Identifier]]s, which provide Data-by-Reference which you find in Object Oriented Programming and Object Oriented Databases in the form of Object Identifiers. |
|||
== See also == |
|||
*[[Object lifetime]] |
|||
*[[Object copy]] |
|||
*[[Design pattern (computer science)|Design patterns]] |
|||
*[[Business object (computer science)|Business object]] |
|||
*[[Actor model]] |
|||
==External links== |
==External links== |
||
*[http://java.sun.com/docs/books/tutorial/java/concepts/object.html ''What Is an Object?''] from ''The Java Tutorials'' |
*[http://java.sun.com/docs/books/tutorial/java/concepts/object.html ''What Is an Object?''] from ''The Java Tutorials'' |
||
{{Software engineering}} |
|||
==References== |
|||
{{Data types}} |
|||
<references /> |
|||
{{Authority control}} |
|||
{{DEFAULTSORT:Object (computer science)}} |
|||
[[Category:Object (computer science)| ]] |
|||
[[Category:Object-oriented programming]] |
[[Category:Object-oriented programming]] |
||
[[Category:Data types]] |
|||
[[Category:Composite data types]] |
|||
[[bs:Računarski objekat]] |
|||
[[cs:Instance třídy]] |
|||
[[da:Objekt (datalogi)]] |
|||
[[de:Objekt (Programmierung)]] |
|||
[[es:Objeto (programación)]] |
|||
[[eo:Objekto (komputiko)]] |
|||
[[fr:Objet (informatique)]] |
|||
[[ga:Oibiacht (ríomhaireacht)]] |
|||
[[ko:객체 (전산학)]] |
|||
[[it:Oggetto (informatica)]] |
|||
[[lt:Objektas (programavimas)]] |
|||
[[nl:Object (informatica)]] |
|||
[[ja:オブジェクト (プログラミング)]] |
|||
[[pl:Obiekt (programowanie obiektowe)]] |
|||
[[pt:Objeto]] |
|||
[[ru:Объект (программирование)]] |
|||
[[simple:Object (computer science)]] |
|||
[[ta:பொருள் (கணினியியல்)]] |
|||
[[vi:Đối tượng (khoa học máy tính)]] |
|||
[[uk:Об'єкт (програмування)]] |
|||
[[zh:对象 (计算机科学)]] |
Latest revision as of 13:40, 31 October 2024
In software development, an object is an entity that has state, behavior, and identity.[1]: 78 An object can model some part of reality or can be an invention of the design process whose collaborations with other such objects serve as the mechanisms that provide some higher-level behavior. Put another way, an object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the problem domain.[1]: 76
A programming language can be classified based on its support for objects. A language that provides an encapsulation construct for state, behavior, and identity is classified as object-based. If the language also provides polymorphism and inheritance it is classified as object-oriented. A language that supports creating an object from a class is classified as class-based. A language that supports object creation via a template object is classified as prototype-based.
The concept of object is used in many different software contexts, including:
- Possibly the most common use is in-memory objects in a computer program written in an object-based language.
- Information systems can be modeled with objects representing their components and interfaces.[1]: 39
- In the relational model of database management, aspects such as table and column may act as objects.[2]
- Objects of a distributed computing system tend to be larger grained, longer lasting, and more service-oriented than programming objects.
See also
[edit]- Actor model – Model of concurrent computation
- Business object – Entity within a multi-tiered software application
- Object lifetime – Time period between the creation and destruction of an object-oriented programming instance
- Object copying – Technique in object-oriented programming
- Semantic Web – Extension of the Web to facilitate data exchange
References
[edit]- ^ a b c Grady Booch; Robert Maksimchuk; Michael Engle; Bobbi Young; Jim Conallen; Kelli Houston (April 30, 2007). Object-Oriented Analysis and Design with Applications (3 ed.). Addison-Wesley Professional. ISBN 020189551X.
- ^ Oppel, Andy (2005). SQL Demystified. McGraw Hill. p. 7. ISBN 0-07-226224-9.
External links
[edit]- What Is an Object? from The Java Tutorials