Object Oriented Programming
Object Oriented Programming, like Functional Programming, is a distinct programming paradigm that is supported by a swath of languages, such as Java and C++. OOP can be used to solve a different set of problems than the ones were solved functionally.
So what exactly is Object Oriented Programming?
OOP views the world in terms of objects that have fields and methods. Fields are the information that individual objects contain. Methods are actions that can be performed by the object.
OOP views the world in terms of objects that have fields and methods. Fields are the information that individual objects contain. Methods are actions that can be performed by the object.
This Object Oriented view of the world can be pretty accurate and is a far cry from the abstract functional view that we've been seeing the world through with OCaml. Indeed, let's first look at the world around us. Instead of seeing mathematical functions floating around, most of us see objects like lamps. These lamps can contain values in fields, such as whether they are on or off. And these lamps can perform actions, like turn_on and turn_off.
Or let's imagine how this object view would be extremely useful programming The Legend of Zelda, a video game with no equal. Link should probably be an object, as should many of the enemies. He should probably have a couple fields to keep track of his health, an array of weapons, the amount of money he's carrying. And Link should probably have a set of methods to indicate that he's moving left, or moving right, or slashing, or throwing a boomerang, or collecting the 8 pieces of the Triforce of Wisdom to rescue Zelda from Ganon (or not).
Many OOP languages (Java, C++, php, Python) are class-based. Classes are a way of adding some abstraction to objects so that we can reuse some code. For instance, lamps might be a class, representing the idea of a lamp. Every individual lamp would be an instantiation of the lamp class. Classes are like a mold, from which you can create a multitude of like objects. We'll dive into more OOP concepts that are related to classes as they come up, such as inheritance, encapsulation, polymorphism, etc.
Or let's imagine how this object view would be extremely useful programming The Legend of Zelda, a video game with no equal. Link should probably be an object, as should many of the enemies. He should probably have a couple fields to keep track of his health, an array of weapons, the amount of money he's carrying. And Link should probably have a set of methods to indicate that he's moving left, or moving right, or slashing, or throwing a boomerang, or collecting the 8 pieces of the Triforce of Wisdom to rescue Zelda from Ganon (or not).
Many OOP languages (Java, C++, php, Python) are class-based. Classes are a way of adding some abstraction to objects so that we can reuse some code. For instance, lamps might be a class, representing the idea of a lamp. Every individual lamp would be an instantiation of the lamp class. Classes are like a mold, from which you can create a multitude of like objects. We'll dive into more OOP concepts that are related to classes as they come up, such as inheritance, encapsulation, polymorphism, etc.
Although OCaml supports the three forms of programming paradigms we've discussed, there's a question of when to mix objects and other types of code in OCaml. It is hoped that the programmer will have the experience to decide on when its best to use one paradigm over another, one language over another, and when to mix them. However, here is one answer in case you are looking for some guidance from Stack Overflow. In general, just stick with what OCaml is best at: Functional Programming. However, OOP is important, so let's cover OOP concepts and extend the power OCaml has.