Object Oriented Programming
Object Oriented Programming
"objects", which are data structures that contain data, in the form of fields, often known
as attributes; and code, in the form of procedures, often known as methods. A distinguishing feature
of objects is that an object's procedures can access and often modify the data fields of the object
with which they are associated (objects have a notion of "this" or "self"). In OO programming,
computer programs are designed by making them out of objects that interact with one
another.[1][2] There is significant diversity in object-oriented programming, but most popular languages
are class-based, meaning that objects are instances of classes, which typically also determines
their type.
Many of the most widely used programming languages are multi-paradigm programming
languages that support object-oriented programming to a greater or lesser degree, typically in
combination with imperative, procedural programming. Significant object-oriented languages
include Python, C++, Objective-C, Smalltalk, Delphi, Java, Swift, C#, Perl, Ruby and PHP.
Contents
[hide]
1Features
o 1.1Shared with non-OOP predecessor languages
o 1.2Objects and classes
o 1.3Dynamic dispatch/message passing
o 1.4Encapsulation
o 1.5Composition, inheritance, and delegation
o 1.6Polymorphism
o 1.7Open recursion
2History
3OOP languages
o 3.1OOP in dynamic languages
o 3.2OOP in a network protocol
4Design patterns
o 4.1Inheritance and behavioral subtyping
o 4.2Gang of Four design patterns
o 4.3Object-orientation and databases
o 4.4Real-world modeling and relationships
o 4.5OOP and control flow
o 4.6Responsibility- vs. data-driven design
o 4.7SOLID and GRASP guidelines
5Criticism
6Formal semantics
7See also
o 7.1Systems
o 7.2Modeling languages
8References
9Further reading
10External links
Features[edit]
Object-oriented programming by definition uses objects, but not all of the associated techniques and
structures are supported directly in languages which claim to support OOP. The features listed
below are, however, common among languages considered strongly class- and object-oriented
(or multi-paradigm with OOP support), with notable exceptions mentioned.[3][4][5][6]
See also: Comparison of programming languages (object-oriented programming) and List of objectoriented programming terms
Variables which can store information formatted in a small number of built-in data
types like integers and alphanumericcharacters. This may include data
structures like strings, lists and hash tables that are either built-in or result from combining
variables using 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 loops and conditionals.
Modular programming support provides the ability to group procedures into files and modules for
organizational purposes. Modules are namespaced so code in one module will not be accidentally
confused with the same procedure or variable name in another file or module.
Classes - 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
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".[7] Sometimes objects represent more abstract
entities, like an object that represents an open file, or an object which provides the service of
translating measurements from U.S. customary to metric.
Each object is said to be an 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, 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 only to 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 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 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. 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, a 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 traits and mixins.