Collection: Component and System

To manage the lifecycle of an application, it's become common practice to divide the system up into components, with dependencies between them. Stuart Sierra's Component library was the first to popularize this concept and can still be considered the reference implementation. The pattern is simple enough, but it does require some knowledge of Clojure's types and records functionality, so those are introduced first. This series also covers the System library, a handy collection of reusable components.

31. Component in Practice
Published 01 June 17

Learn how to incorporate Component in a real world project. This episode is a bit of grab bag. It shows how to set up a -main function and how to use it, how to use reloaded.repl and tools.namespace for a better REPL workflow. You get introduced to the Suspendable protocol that complements Component’s Lifecycle protocol. Finally it shows how to streamline your configuration with Aero.

26. Component and System
Published 07 March 17

Stuart Sierra’s Component is a small library that can have a big impact on the structure and architecture of your application. In this episode you learn how you can use it to create components, and manage dependencies. You will create a Jetty and an Endpoint component, and use the PostgreSQL component from the System project.

24. defrecord and defprotocol
Published 30 January 17

With records, Clojure has introduced a way to create struct-like objects, while avoiding some of the problems encountered in object orientation. Records don’t hide their data behind custom interfaces, but instead partake in the abstractions that Clojure’s own data types are built on, so that code can treat treat a record like a regular Clojure data type.

Protocols are Clojure’s take on abstract interfaces. They make it possible to extend preexisting types to new methods, and extend preexisting methods to new types, thus avoiding the expression problem.

23. deftype and definterface
Published 19 January 17

Clojure is built on a well thought out set of abstractions. To implement these, it makes use of the ability to define abstractions in the host language, namely Java interfaces, and the high-performance polymorphism that they provides.

As a Clojure programmer you don’t have to resort to Java to achieve the same thing. All the facilities are there to create interfaces, and to create types that implement interfaces, getting you as close to the JVM as you need to be.