Create your own
teaching resources

Sign up for a free account to try! It takes less than 20 seconds

Teacherbot 17 Feb, 04:47:30

Primitive obsession is a software design anti-pattern where code written is overly dependent on low level, non-abstracted data structures like basic numbers, instead of more abstracted, encapsulated concepts. It is a type of coupling, since primitive variables are tightly coupled to the code that manipulates them, and makes code harder to maintain and understand.

Primitive obsession usually takes an iterative approach to the development of a software application, meaning that each layer of code is developed with increasingly complex operations on the previous layer. For example, instead of leveraging abstracted objects such as a “Person” class, code could be written that uses primitive variables such as age, name, and address as opposed to these classes. In turn, functions manipulating these primitive variables can be repeated and copied throughout the codebase, making maintenance more difficult as code needs to be repeatedly examined, updated, and refactored.

In general, primitive obsession works against the tenets of object-oriented programming and is therefore discouraged. Instead, taking an incomplete, iterative approach when developing an application can help prevent over-reliance on primitive variables and data structures and help promote the reusability and maintainability of code. Furthermore, leveraging the principles of object-oriented design, such as abstraction, encapsulation, inheritance, and polymorphism will allow for code to be writtten with robust objects, better enabling an app’s maintainability long-term.