This question changed my view on object-oriented programming forever. It was a few years ago when I accidentally found the answer I hadn’t even sought. Eventually, however, it was surprisingly simple, yet enlightening. Unlike me back then, I assume you aren’t here by mistake, so I hope to shed some light on the concept of context and, ideally, inspire you to build better-designed software.

Before I start, let me mention that you shouldn’t expect much academic theory (in fact, you shouldn’t expect it at all) and terms used in their strict book definitions. My aim is not to give one of those dull lectures devoid of practical usage, but to share my knowledge and understanding of the context in the… context of OOP, and how it helps to design clearer architecture and more user-friendly APIs, libraries, etc. Let me emphasize “share” as I’m far from “teaching” you the one and only way to understand this topic.

All code samples are written in Kotlin for two reasons. Number one — currently it’s the programming language in which I write the most. Moreover, I got the idea for this article while working on my set of Android libraries, thus it’s easier to find/come up with real-world examples. The second reason is that the syntax of Kotlin handles using contexts and defining DSL-like tools in the most impressive and friendly manner I’ve seen. Yeah, Kotlin fanboi confirmed. 😅 Okay, that’s a long preface. Let’s get started.

#object-oriented #kotlin #context #software-architecture #software-design

What is the context in object-oriented programming?
1.65 GEEK