Object-Oriented Programming
Posts
Emerging Objects
Building a simple object system out of closures
Object-oriented programming and functional programming imply each other. While encoding closures as objects is a well-known technique (see the command pattern, and e.g. Functors in C++), using closures to implement objects is a bit more unusual.
In this post, I will explore creating a simple object system in JavaScript, using only the functional parts.
Dynamic vs. Static Dispatch
This article explains the difference between dynamic dispatch (late binding) and static dispatch (early binding). We'll also touch on the differences in language support for virtual and static methods, and how virtual methods can be circumvented.
MOPping it up
Building a simple Metaobject-Protocol
Many languages make a distinction between objects and classes. But shouldn't everything – including classes – be an object in a pure object-oriented language? Some languages like Smalltalk, Common Lisp, and Ruby manage just that and offer a complete and flexible Metaobject-Protocol. Others such as Java only offer a read-only object protocol commonly called “introspection” or “reflection”.
In this post, I'll explore how to create a simple Metaobject-Protocol where classes are objects – all without creating infinite loops. We'll be using a previous post's JavaScript object encoding as a basis for this MOP.
Interface Dispatch
Virtual method calls are simple: you just look up the method slot in a vtable and call the function pointer. Easy! Well, not quite: interfaces present a kind of multiple inheritance, and things quickly become complicated.
This post discusses interface method calls in C++ (GCC), Java (OpenJDK/HotSpot), C# (CLR), Go, and Rust.
It is an expanded version of my answer on Software Engineering Stack Exchange on Implementation of pure abstract classes and interfaces.
Dump notes