10 Foundational subsystems

This chapter covers

  • How to implement logging
  • Abstracting subsystems with the Typed-Untyped design pattern
  • Advanced approaches to state handling
  • How to safely utilize resources using the Bracket pattern

Different application frameworks may show many similarities in what they offer to developers. Once a new framework enters the development scene, the same subsystems should be implemented repeatedly. Developers who have worked at several companies may confirm that every big-enough project has its own implementation in terms of logging, resource-acquisition mechanism, and integration with external subsystems. Unique implementations are inevitable because implementing a universal approach suitable for all the cases, languages, and domains is nearly impossible.

In this chapter, we will implement some important subsystems such as logging, and given that our main focus is on software design and approaches, we’ll find a couple of new design patterns applicable to this widespread topic. We’ll also learn about advanced state handling and touch briefly on the problem of proper resource management.

10.1 Logging subsystem

Logging is certainly the most essential subsystem of every application framework. It may even be the only subsystem that all the projects have in common. Moreover, it may be the only subsystem we repeatedly introduce and implement during our developer careers.

All the logging subsystems are more or less the same. We can expect to see an interface that

10.1.1 Logger design

10.1.2 Global static mutable logger

10.1.3 Structured logging interface

10.1.4 Structured logging implementation

10.2 Advanced state management

10.2.1 Wrapping STM with the Typed-Untyped design pattern

10.2.2 State subsystem and logging

10.2.3 Trackable state

10.3 Resource initialization and the Bracket pattern

10.3.1 RAII in OOP languages

10.3.2 The Bracket pattern

Summary