Object-Oriented Programming: Features
Object-Oriented Programming: Features
Object-Oriented Programming: Features
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 multiparadigm 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.
Languages that support object-oriented programming typically use inheritance for code reuse and
extensibility in the form of eitherclasses or prototypes. Those that use classes support two main
concepts:
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 an 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.
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 there are multiple methods that might be run for
a given name (which may require some language support), it is known as 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[edit]
If a class disallows calling code from accessing internal object data and forces access through
methods only, this is a strong form of abstraction or information hiding known asencapsulation.
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 asprotected (which typically allows access from other objects of the same
class, but not objects of a different class). In other languages (like Python) this is enforced only by
convention (for example, naming "private" methods starting with an underscore). This is useful
because it prevents the 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 often used as a technique for encouraging decoupling.
Polymorphism[edit]
Subtyping, a form of polymorphism, is when calling code can be agnostic as to whether an object
belongs to a parent class or one of its descendants. For example, a function might call
"make_full_name()" on an object, which will work whether the object is of class Person or class
Employee. This is another type of abstraction which simplifies code external to the class hierarchy
and enables strong separation of concerns.
Open recursion[edit]
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 late-bound; it allows a method defined in one class to invoke another method that is
defined later, in some subclass thereof.
OOP languages[edit]
This section does not cite any references or sources. Please help improve this section
by adding citations to reliable sources. Unsourced material may be challenged
and removed. (August 2009)
See also: List of object-oriented programming languages
Simula (1967) is generally accepted as the first language with the primary features of an object-oriented
language. It was created for making simulation programs, in which what came to be called objects were the
most important information representation. Smalltalk (1972 to 1980) is arguably the canonical example, and the
one with which much of the theory of object-oriented programming was developed. Concerning the degree of
object orientation, the following distinctions can be made:
Languages designed mainly for OO programming, but with some procedural elements.
Examples: Delphi/Object Pascal, C++, Java, C#, VB.NET.
Languages that are historically procedural languages, but have been extended with some OO
features. Examples: Pascal, Visual Basic (derived from
BASIC), MATLAB,Fortran, Perl, COBOL 2002, PHP, ABAP, Ada 95.
Languages with most of the features of objects (classes, methods, inheritance), but in a distinctly
original form. Examples: 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 andprototype-based languages.
Examples: Modula-2, Pliant, CLU, JavaScript, Lua.
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.
Fields defining the data values that form messages, such their length, codepoint and data values.
Objects and collections of objects similar to what would be found in a Smalltalk program for messages
and parameters.
Managers similar to AS/400 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 Distributed Relational Database Architecture (DRDA).
Design patterns[edit]
Challenges of object-oriented design are addressed by several methodologies. Most common is known as
the design patterns codified by Gamma et al.. More broadly, the term "design patterns" can be used to refer to
any general, repeatable solution to a commonly occurring problem in software design. Some of these
commonly occurring problems have implications and solutions particular to object-oriented development.
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
Both object-oriented programming and relational database management systems (RDBMSs) are extremely
common in software today. 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 objectrelational impedance mismatch. There are a number of approaches to cope with this problem, but no general
solution without downsides.[23] One of the most common approaches is object-relational mapping, as found
in IDE languages such as Visual FoxProand 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.
Open/closed principle
GRASP (General Responsibility Assignment Software Patterns) is another set of guidelines advocated by Craig
Larman.
Criticism[edit]
The OOP paradigm has been criticised for a number of reasons, including not meeting its stated goals of
reusability and modularity,[33][34] and for overemphasizing one aspect of software design and modeling
(data/objects) at the expense of other important aspects (computation/algorithms). [35][36]
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. [33] The latter point is reiterated by Joe
Armstrong, the principal inventor of Erlang, who is quoted as saying:[34]
The problem with object-oriented languages is they've got all this implicit environment that they carry around
with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.
A study by Potok et al. has shown no significant difference in productivity between OOP and procedural
approaches.[37]
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; [38] however, Date and Darwen have
proposed a theoretical foundation on OOP that uses OOP as a kind of customizable type system to
support RDBMS.[39]
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. [40]
Alexander Stepanov compares object orientation unfavourably to Generic programming:[35]
I find OOP technically unsound.. It attempts to decompose the world in terms of interfaces that vary on a single
type. To deal with the real problems you need multisorted algebras families of interfaces that span multiple
types. I find OOP philosophically unsound. It claims that everything is an object. Even if it is true it is not very
interesting saying that everything is an object is saying nothing at all.
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." [41]
Formal semantics[edit]
See also: Formal semantics of programming languages
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:
abstract data types (which have existential types) allow the definition of modules but these do not
support dynamic dispatch
recursive types
encapsulated state
inheritance
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<: that deal with mutable objects have been
studied;[45] 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[45] 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 and scoping sugar on top. Inheritance can be
performed by cloning the maps (sometimes called "prototyping").