Friday, May 25, 2012

Primitive Obsession:I will design all from scratch!

This is one of the primary tendency of every fresher developer or programmer, I my self is not out of the boundary, After starting the programming I was also kind of had the same tendency, I didn’t have much idea about the vast class library and functionality the c++, java or c# has to offer, rather I used the basic and primitive data structure and ideas and techniques that I learned while coding c.

This simple ignorance is some time called “Primitive Obsession”.

Here is what “codinghorror” has to say about “Primitive Obsession”,

“Don't use a gaggle of primitive data type variables as a poor man's substitute for a class. If your data type is sufficiently complex, write a class to represent it. ”

Code that has primitive obsession has the following phenomena 

  • use of primitives data type (like integers or strings) for solving complex problem.
  • use of low-level methods to perform operation on data.

Eventually we loose a higher level of abstraction.

One simple example in c# could be build a list of objects, we could build a class to keep a specific type of data and then expose different methods and properties to support the class,


We can use a List<T> to keep the object, where what ever we need from a list is there. I think you got the idea.


No comments:

Post a Comment