Composition in The World of Software
My initial impression was that composition was a new idea that was popularized through the rise of Functional Programming. But then I started looking into dependency injection, which apparently had its origins in Java. This led me to the concept of favoring “Composition over Inheritance”, a best practice in object-oriented Java. More recently, I came across a hackerrank problem named “Roads and Libraries”, which basically boils down to figuring out the different components in the graph.
At a higher-level, you have the concept of modularity. It more or less aims to solve the same problems that object-orientation does: visibility, accessibility, cohesion, and coupling. In other words, a good separation of concerns. But where object-orientation is “programming in the small”, modularity is “programming in the large”. You utilize object-orientation to define your classes and how they relate to each other, then use modularity to encapsulate these classes and define this collection’s relationship with other similar sets of classes.
I’m currently on a project that utilizes an implementation of the OSGi specification, which is a standard for modularity in the Java ecosystem. I’ll be working on a large-scale project with classes numbering in the hundreds. It’s an exciting opportunity for me to immerse myself in composition as it relates to systems design, similar to how Docker containers are architected.
I can’t wait to see what’s in store for me in the coming weeks.
Here are some great reads on the concepts of composition and modularity: