Object-oriented (OO) programming is a way of structuring code by combining instructions and data into self-contained “objects”. It was developed in the 1950s and 1960s, and today is arguably more popular than traditional procedural programming.
What programming languages are object-oriented?
Early object-oriented languages included Sketchpad, Smalltalk and C++. Today, the most widely used OO platforms are C# and Java. Both can be used to create applications of any type, which can run on all major computer platforms.
Python is another popular choice for general-purpose OO programming, thanks to its easy-to-read syntax and a wealth of freely available libraries. Other OO languages are focused on the web: PHP dynamically generates and customises web pages, while Ruby is often used to build dynamic applications that are accessed through a web browser.
How does object-oriented programming work?
An object is a virtual structure that contains a set of member variables – similar to a database record – plus any number of code blocks (“methods”). These methods can manipulate the internal variables and perform other object-specific functions. Programs function by creating objects as needed, and accessing their variables and methods.
For example, the software used by a car hire service could create an object representing each vehicle on its books. Each one would be created from a standard blueprint (“class”), which might include member variables to store details of the vehicle’s model and registration details, and a method to allow the operator to check and update reservation details. When new vehicles were acquired, corresponding objects could be created instantly using the same class.
What are the benefits of object-oriented programming?
Creating a working OO program can be very quick and easy: once a class has been defined, you can spawn and work with any number of objects. Classes can be conveniently reused across multiple projects, and subclasses can be defined that build on the parent class. In the example above, “car” and “van” classes could be based on the general “vehicle” class, with the latter adding a variable for carrying capacity.
The object-oriented approach can also make updating and troubleshooting programs much simpler, as member variables and methods can be added or changed for all objects by updating the parent class.
Meanwhile, the overall program flow can be simpler and more secure. That’s because the only information that can be accessed from an object is what is exposed by its public member variables, and the only actions available are the ones defined by its methods. This minimises the scope for unexpected behaviours or vulnerabilities.
What are the downsides of object-oriented programming?
Because of the code duplication involved, OO programs that work with large numbers of objects may require more resources. As a result, they may run more slowly than procedural alternatives.
Object-oriented concepts can also be difficult to grasp. While there’s no shortage of qualified developers, mastering an object-oriented language may require more experience and training than a procedural language.
- Object-oriented programming combines data and code into self-contained units
- An object-oriented approach can make it quick and easy to develop and update complex programs
- Popular object-oriented languages include C#, Java and Python
- Programs created in object-oriented languages may be less resource-efficient than procedural code.
Nathalie Parent, Chief People Officer at Shift Technology: “HR is the conscience of an organisation”
For more than 30 years, Nathalie Parent has led global HR teams, working primarily with software companies. Today she’s Chief People Officer at Shift Technology
Amazon introduces new storage class that makes it cheaper to store rarely used files
Robot carers are real, but caregiving has bigger problems, writes Richard Trenholm in this FlashForward edition