From the course: Java Refactoring Best Practices
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Refactoring primitive obsession - Java Tutorial
From the course: Java Refactoring Best Practices
Refactoring primitive obsession
- [Instructor] The next code smell we're going to discuss is the primitive obsession. This is a code smell that indicates the use of primitive data types and strings instead of creating custom objects. This can make the code harder to read and maintain and as a bonus disadvantage it often results in duplicate code. Just like the bloaters, the problem doesn't typically arise in a day. It happens during a lot of small moments. It's easy to just create a quick primitive field instead of defining a small class for it. And if you do that a lot, this turns into something called primitive obsession. Primitive obsession doesn't mean that you start to think about primitive 24/7 and that you dream about them. It means that your class is very messy and overuses primitives by a lot. For example, to use primitives to simulate a real type instead of creating this real type we use a primitive with a very recognizable name. Here's a…
Contents
-
-
-
-
-
-
(Locked)
Refactoring bloaters4m 45s
-
(Locked)
Refactoring primitive obsession3m 48s
-
(Locked)
Refactoring incorrect object-oriented programming3m 45s
-
(Locked)
Refactoring excessive coupling2m 50s
-
(Locked)
Challenge: Refactor the legacy code2m 28s
-
(Locked)
Solution: Refactor the legacy code3m 28s
-
(Locked)
-