
In other words, different objects may react to the same message in different ways. There are five fundamental properties that differentiate OOP from other styles: Abstraction The details of the implementation are hidden in the object, and the external interface is just the set of publicly accessible methods.ĭynamic lookup When a message is sent to an object, the method to be executed is determined by the implementation of the object, not by some static property of the program.
#Polymorphism java example shape of objects code#
The code definition behind an object is called a class, and objects are constructed from a class definition by calling a constructor with the data that the object will use to build itself. Each object contains some data stored in fields and has method functions that can be invoked against the data within the object (also called “sending a message” to the object).

Object-oriented programming (often shortened to OOP) is a programming style that encapsulates computation and data within logical objects. In the next chapter, Chapter 13, Classes, we’ll introduce you to classes and inheritance. In this chapter, we’ll introduce you to OCaml objects and subtyping. There are objects, classes, and their associated types. In addition, OCaml also supports object-oriented programming.

We’ve already seen several tools that OCaml provides for organizing programs, particularly modules. This chapter was written by Leo White and Jason Hickey.
