Observability

Allow objects to work collaboratively

As said previously, observability is a feature, a capability of an object.

Because objects want to work in a choreographed manner more than in an orchestrated manner, they don't want anyone above telling them what to do.

In order to work collaboratively, they need to exchange messages with one another, in real time.

Think microservices : it's about APIs communicating together using asynchronous messages.

That's the pinacle of object-orientation. When in doubt, look at microservices : they're doing objects right !

There's many ways to implement observability, but the most flexible solution is to use an event dispatcher and to implement a publish/subscribe mechanism.

There's a rough sketch.

class NavigationBar {
    constructor(eventDispatcher) {
        eventDispatcher.on("newMessages", this.incrementUnreadMessages.bind(this));
        eventDispatcher.on("messagesViewed", this.decrementUnreadMessages.bind(this));
    }
    
    incrementUnreadMessages() {
        // code
    }
    
    decrementUnreadMessages() {
        // code
    }
}

class ChatBox {
    receiveMessages(messages: Message[]) {
        this.eventDispatcher.emit("newMessages", messages);
    }
    
    focus() {
        this.eventDispatcher.emit("messagesViewed", ...);
    }
}

Imagine a website like LinkedIn or Facebook where you can open multiple message boxes and maintain a count of unread messages on the navigation bar.

This structure is collaborative : each chatbox can emit events if they know there might be some interested parties.

Alternatively, NavigationBar can listen to these events.

And either know about each other.

And not a single master class to coordinate them.

Observability allows them to work in tandem and to evolve independently as their respective needs grow.

Last updated