More and more often, I design my code around object sequences rather than around individual objects. Having a single interface that manages the whole sequence brings a lot of flexibility and optimization opportunities on the implementation side. That’s exactly where the usual OOP methodology fails as all the common OOP idioms deal with 1-1 object relations and blindly insist on per-object encapsulation.

So it’s time to move a bit towards DOD. Here, I’m going to show a table idiom I’ve been using quite often recently. The idea is that the table holds all the objects in a sequence indirectly addressed via index (or generally via handle). There’s no per-object interface, objects are manipulated through table’s interface using a bunch of setters. Each object consists of a public and private state. Both states are managed and kept in sync internally via the table. The best thing is that the full object’s public state can be obtained by a single get() call that returns a const reference to the state struct, this call is essentially for free and can be easily inlined. All the bookkeeping is atomically done in setters. See the example below to get the idea: