Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

OOP, encapsulation and bulk loading

Name: Anonymous 2010-07-04 19:10

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.

Name: Anonymous 2010-07-07 17:02

>>7
You need to use the MVC pattern to decouple interface and presentation logic from system internals. Validation should be performed by the controller. The class you are loading should implement some sort of Serializable interface, which will allow you to just create new instances given the serial data. The the controller can react to a "load from file" event, by opening the file, creating all the new instances from the serialized data and passing these off to the model.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List