When is a class with no methods poor design?
From what I've read, a class with no methods (i.e. no behaviors) (AKA dumb class) is poor design, with the exception of Data Transfer Objects (DTOs). This is due to the purpose of DTOs being to reduce the overhead when transferring data to a remote interface (Local DTO). There appears to be some debate on DTOs and Plain Old Class Object (POCO VS DTO) and debate going further to anemic design (Anemic Model Domain).
So, where the dumb class in question is a local object (i.e. not for transferring data) are you generally better to refactor the attributes of the dumb class and implement them as a collection (e.g. Dictionary)? To quote Bill K (How can i write DAOs for resources with extensible properties), "Where you would have used an object, use a hashtable. For your attribute names use keys, for the attribute values, use the value in the hashtable."
My thinking when designing this dumb class was that of composition. Another class is composed of multiple dumb class objects (i.e. a collection of dumb class objects). Was my thinking wrong? If I am to implement the dumb class as a collection, I would have a collection of a collection of attributes.
I am of the understanding collections of collections of collections etc. is also poor design. Is there some guiding principle to balance these apparent choices of poor design?
As always any insight or guidance is appreciated.
Regards Shannon
Where you would have used an object, use a hashtable
- I'm sorry that is nonsense. Dictionaries are magic-string based, prone to all sorts of subtle errors, and also require additional casting of everything. That cannot be compared to the simplicity and beauty of a strongly typed object model. Whoever said that is either not thinking in terms of strongly typed languages such as C# or doesn't really understand OOP in general. – WesleeDictionary<string, List<Dictionary<string,object>>>
that sucks. a LOT. The amount of nested generics plus the amount of casting stuff to other stuff and redundant type checks you need will turn your otherwise "simple properties" into an horrible behemoth monstrosity. Use a strongly typed object model. Always. – Weslee