Principles Of Programming
Object Oriented Programming
Object Oriented Programming, also known as OOP, is a way of coding using the idea of ‘objects’ to represent data and methods. It differs from other forms of programming as it organises design around data rather than functions and logic. An object is anything within the code which can be defined as a data field which has unique attributes and behaviour. This allows developers to focus on the objects they wish to manipulate rather than what is required to manipulate them. OOP has become popular since the term was coined by Alan Kay in the mid 1960’s [1] due to the fact that it succeeds in catering to programs which are large, complex and are being actively updated and maintained [2].
Object Oriented Programming is built on 4 base principles: Encapsulation, Abstraction, Polymorphism and Inheritance. Encapsulation is the process of ‘information hiding’ where an object only provides access to essential information for manipulation through provided methods, without giving access to all of its internal details. In practice, this is seen when certain variables and functions are delegated as ‘private.’ This is so that the rest of the code can make use of these variables and functions but cannot interfere or change them [3].
Abstraction is similar to Encapsulation as they both function to withhold certain key data from other functions within the programme. However, where Encapsulation solves this issue at the point where the information is implemented, Abstraction does so at the point where the information is first defined [4]. Process Abstraction is when the object doesn’t require access to every function within the code. For example, when driving a car, you need to know how to start it, how to accelerate and how to slow down but you don’t need to know how the engine the works. In this example, the engine would be a private function whereas the rest would all be public functions [5]. The main purpose of Abstraction is to reduce the complexity of a programme and also reduce the amount of processing power needed to run it [4].
Polymorphism is a programming languages ability to process data based on the type or class of the data. Polymorphism literally means ‘many forms’ and so when applied to programming, this means that a function can be utilised in different ways. A real-world example can again be applied to a car; a car has many gears and when you change between them the car gets faster or slower. In this case, the engine is still carrying out the same basic function throughout however the effect that the function has changes dependent on which gear has been selected [6].
Inheritance is a mechanism where one class or set of data can be derived from another class. This process means that all ‘child’ classes derived from the original ‘parent’ class share the same base attributes [7]. For example, a game may have a parent class called ‘enemy’ which causes damage, roams around the level etc. Child classes may then be created called ‘small enemy’ ‘medium enemy’ and ‘large enemy’ which all have varying degrees of damage, but all have the same basic functions.
References
- https://medium.com/javascript-scene/the-forgotten-history-of-oop-88d71b9b2d9f
- https://searchapparchitecture.techtarget.com/definition/object-oriented-programming-OOP
- https://introprogramming.info/english-intro-csharp-book/read-online/chapter-20-object-oriented-programming-principles/
- https://www.guru99.com/java-data-abstraction.html
- https://www.journaldev.com/33191/what-is-abstraction-in-oops
- https://beginnersbook.com/2013/03/oops-in-java-encapsulation-inheritance-polymorphism-abstraction/
- https://stackify.com/oop-concept-inheritance/
