From the course: Expert Domain-Driven Design (DDD) Implementation in .NET

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Avoiding the primitive obsession anti-pattern

Avoiding the primitive obsession anti-pattern - .NET Tutorial

From the course: Expert Domain-Driven Design (DDD) Implementation in .NET

Avoiding the primitive obsession anti-pattern

- [Instructor] When we develop software using object-oriented programming, it's very common to define classes with properties that use the data types provided by the development platform we're working with. In this case, .NET and the common type system. Give us all these data types such as int, bool, daytime, string, decimal, double, and so on. So here, let's add other properties to the Pet class. So for example, let's add color, and you can see that I'm using string and let's add weight. I'm using decimal. Sometimes we also use enums to model our classes. Let's create a new enum called sex of pet. So public enum SexOfPet, and let's add Male, Female, and let's add a new property, SexOfPet with the same name. Just like this. This is fine. However, an enum is basically just a list of named integers, right? The problem with basic data types is that they're general purpose and don't convey any business logic or intent. If we rely on them to model our classes, we risk falling into the trap…

Contents