Object-oriented programming
Published:
Object-oriented programming (OOP) is a programming paradigm based on the concept of “objects”, which may contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. A 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 OOP, computer programs are designed by making them out of objects that interact with one another. There is significant diversity of OOP languages, but the most popular ones are class-based, meaning that objects are instances of classes, which typically also determine 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 Java, C++, C#, Python, PHP, Ruby, Perl, Delphi, Objective-C, Swift, Common Lisp, and Smalltalk.
There is still some controversy raised by Alexander Stepanov, Richard Stallman and other programmers, concerning the efficacy of the OOP paradigm versus the procedural paradigm. The need for every object to have associative methods leads some skeptics to associate OOP with software bloat; an attempt to resolve this dilemma came through polymorphism.
The objects and class hierharchies of data come as:
- 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
The main features of OOP are:
- Encapsulation: Parts of code can be invisible or accesible to others depending on the encapsulation hierchies we want to apply. Some classes could have data and its methods private, public or even _protected (acessible from some classes, tipically from objects of the same class).
- Composition, inheritance, and delegation: That features allows programmers to factorize some parts of the classes and create complex structures in which some objects share some class properties with some other objects but other non-specific class methods are not shared.
- Polymorphism: 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. This is another type of abstraction which 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.
See also
Books
- Rumbaugh, James, et al. Object-oriented modeling and design. Vol. 199. No. 1. Englewood Cliffs, NJ: Prentice-hall, 1991.
- Gamma, Erich; Johnson, Ralph; Vlissides, John; Helm, Richard (1994). Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley Professional
- Freeman, Steve; Pryce, Nat (2009). Growing Object-Oriented Software, Guided by Tests. Addison-Wesley Professional
- Booch, Grady; Maksimchuk, Robert A.; Engle, Michael W.; Young, Bobbi J.; Conallen, Jim; Houston, Kelli A. (2007) Object-Oriented Analysis and Design with Applications. Addison-Wesley Professional
- Jacobson, Ivar; Jonsson, Patrik; Christerson, Magnus; Overgaard, Gunnar (1992). Object-Oriented Software Engineering. Addison-Wesley Professional
- Blaha, Michael R.; Rumbaugh, James (2004). Object-Oriented Modeling and Design with UML. Prentice Hall
- Lafore, Robert (2001). Object-Oriented Programming in C++. Sams Publishing
- Metz, Sandi (2012) Practical Object Oriented Design in Ruby.