Is there any reason to use "container" classes?

Posted by Michael on Programmers See other posts from Programmers or by Michael
Published on 2010-12-27T14:35:37Z Indexed on 2010/12/27 14:58 UTC
Read the original article Hit count: 377

I realize the term "container" is misleading in this context - if anyone can think of a better term please edit it in.

In legacy code I occasionally see classes that are nothing but wrappers for data. something like:

class Bottle {
   int height;
   int diameter;
   Cap capType;

   getters/setters, maybe a constructor
}

My understanding of OO is that classes are structures for data and the methods of operating on that data. This seems to preclude objects of this type. To me they are nothing more than structs and kind of defeat the purpose of OO. I don't think it's necessarily evil, though it may be a code smell.

Is there a case where such objects would be necessary? If this is used often, does it make the design suspect?

© Programmers or respective owner

Related posts about java

Related posts about code-quality