So I have this class that represents a thing that can be created or loaded and saved, it's nice and encapsulated - it has a couple of properties that are private with public getters and setters. Nothing special, when I load this thing - properties get set directly, when I create it - I use property setters that do some sanitization and validation.
Now the question. I also, for performance reasons, need to bulk load these things.
1st, where could I put such method? It doesn't really belong on the things class, I mean static <Thing[]>Thing.Load(keys[]) doesn't look right at all.
2nd, how would I initialize these things? I don't want to use the public setters, because, as I mentioned, they do some checking that's necessary only the first time, when I'm loading it from the storage, everything is already sane. I also don't want to expose the properties publicly. Currently I have a constructor that takes all properties and sets them directly, but that's ugly.
It's strange that no one suggested this, but obviously what you do to solve the 2nd problem, is to leave the public setters as they are - public, but instead of having private(C#)/protected(C#)/private(Java) properties you make them internal(C#)/protected(Java)! This way when you bulk load the Things you can use properties directly, bypassing setters.
Name:
Anonymous2010-07-10 11:02
>>1
Hackish way: reinterpret_cast. SCALABLE ENTERPRISE SOLUTION: Move the validation to a separate class.