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-04 20:28

To be honest, I would have made it a static method. But then again, I still think that FP can take over the mainstream, so what do I know.

Name: Anonymous 2010-07-04 22:18

Oh god, this is a C++ question, isn't it.

Name: Anonymous 2010-07-07 15:52

1) You're bulk loading them. Are they not then put in a collection? Would this not be a method of your custom collection class/wrapper?

2) If it works, it works. More of your implementation would help determine what would be best.

Name: Anonymous 2010-07-07 16:07

Befriend with your container and have an appropiate ctor for that?

Name: Anonymous 2010-07-07 16:24

Name: Anonymous 2010-07-07 16:30

>>4
I didn't want to add a class just for the sake of one method, but I guess you're right. That seems like a reasonable solution.

OK, so, users can create and edit these things, there's already validation in user interface with friendly error messages, but in case someone got around the GUI, I also do validation with setters and throw exceptions if something isn't right. So the problem is these setters, they assume that data comes from untrusted source, which isn't the case when I'm bulk loading these things (creating a new instance and setting properties). Basically I have two cases, one is when the data comes from user and I need to validate it and other when the data comes from storage and validation should be skipped. I can think of a couple of solutions, but I'm not sure which way to go. 1) I could add a property that specifies whether validation should be done. 2) I could derive user side Thing from internal Thing, where internal doesn't do validation. 3) I could have multiple method for setting properties Thing.SetFoo() and Thing.SetAndValidateFoo(). 4) I could have a constructor that takes all properties and sets them directly (this is what I do currently). 5) I could move validation off the setters and into a Validate() method. What do you think?

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.

Name: Anonymous 2010-07-07 20:04

>>8
I think you're over-complicating things, no need to throw MVC at everything. Objects should know how to validate their inputs.

Name: Anonymous 2010-07-08 1:49

>>6
At some point, there is just going to be the "Java design pattern" which is the cartesian product of all programs every successfully compiled into java bytecode.

Name: Anonymous 2010-07-08 2:00

I use the Memento design pattern purely for its side-effects.

Name: Anonymous 2010-07-08 3:14

>>6
I raged hard.

Name: Anonymous 2010-07-08 9:56

Name: Anonymous 2010-07-08 11:48

>>13
woah his face done got encapsulated

Name: Anonymous 2010-07-08 13:34

>>13
If that isn't a mask, then I am a terrible person

Name: Anonymous 2010-07-08 14:32

>>15
That's what having pi/2 heads looks like.

Name: Anonymous 2010-07-08 14:34

Have you read you're [b][i][u]DESIGN PATTERNS[u][/i][/b] today?

Name: Anonymous 2010-07-08 14:35

Name: Anonymous 2010-07-08 14:41

[b][i][u]DESIGN PATTERNS[u][/i][/b]

Name: Anonymous 2010-07-08 14:42

DESIGN PATTERNS

Name: Anonymous 2010-07-08 14:42

DESIGN PATTERNS

Name: Anonymous 2010-07-08 14:46


     /   __/     /   __/     /   __/     /   __/     /   __/     /   _
__   \__/  \__   \__/  \__   \__/  \__   \__/  \__   \__/  \__   \__/
  \__/  \     \__/  \     \__/  \     \__/  \     \__/  \     \__/  \
__/     /   __/     /   __/     /   __/     /   __/     /   __/     /
  \__   \__/  \__   \__/  \__   \__/  \__   \__/  \__   \__/  \__   \_
     \__/  \     \__/  \     \__/  \     \__/  \     \__/  \     \__/
   __/     /   __/     /   __/     /   __/     /   __/     /   __/   
__/  \__   \__/  \__   \__/  \__   \__/  \__   \__/  \__   \__/  \__ 
  \     \__/  \     \__/  \     \__/  \     \__/  \     \__/  \     \_
  /   __/     /   __/     /   __/     /   __/     /   __/     /   __/
  \__/  \__   \__/  \__   \__/  \__   \__/  \__   \__/  \__   \__/  \_
__/  \     \__/  \     \__/  \     \__/  \     \__/  \     \__/  \   
     /   __/     /   __/     /   __/     /   __/     /   __/     /   _
__   \__/  \__   \__/  \__   \__/  \__   \__/  \__   \__/  \__   \__/
  \__/  \     \__/  \     \__/  \     \__/  \     \__/  \     \__/  \
__/     /   __/     /   __/     /   __/     /   __/     /   __/     /
  \__   \__/  \__   \__/  \__   \__/  \__   \__/  \__   \__/  \__   \_
     \__/  \     \__/  \     \__/  \     \__/  \     \__/  \     \__/
   __/     /   __/     /   __/     /   __/     /   __/     /   __/   
__/  \__   \__/  \__   \__/  \__   \__/  \__   \__/  \__   \__/  \__ 
  \     \__/  \     \__/  \     \__/  \     \__/  \     \__/  \     \_
  /   __/     /   __/     /   __/     /   __/     /   __/     /   __/
  \__/  \__   \__/  \__   \__/  \__   \__/  \__   \__/  \__   \__/  \_

Name: Anonymous 2010-07-08 14:47


 |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___
    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|
_  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |
_|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_| 
 |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___
    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|
_  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |
_|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_| 
 |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___
    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|
_  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |
_|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_| 
 |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___
    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|
_  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |
_|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_| 
 |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___
    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|
_  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |
_|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_| 
 |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___
    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|_|    _|
_  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |___  | |
     |       |       |       |       |       |       |       |       |

Name: Anonymous 2010-07-08 14:47


_|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_  
 |       |       |       |       |       |       |       |       |   
    _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|
     |       |       |       |       |       |       |       |       |
_|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_  
 |       |       |       |       |       |       |       |       |   
    _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|
     |       |       |       |       |       |       |       |       |
_|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_  
 |       |       |       |       |       |       |       |       |   
    _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|
     |       |       |       |       |       |       |       |       |
_|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_  
 |       |       |       |       |       |       |       |       |   
    _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|
     |       |       |       |       |       |       |       |       |
_|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_  
 |       |       |       |       |       |       |       |       |   
    _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|
     |       |       |       |       |       |       |       |       |
_|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_     _|_  
 |       |       |       |       |       |       |       |       |   

Name: Anonymous 2010-07-08 14:55

>>22-24
I'll be impressed when I start seeing Penrose tilings.

Name: EXPERT TESSELATOR 2010-07-08 15:03

>>25
Fuck off, ``Xarn''.

Name: Anonymous 2010-07-08 15:04


                      ____                   
                 ____ \__ \
                 \__ \__/ / __
                 __/ ____ \ \ \    ____
                / __ \__ \ \/ / __ \__ \
           ____ \ \ \__/ / __ \/ / __/ / __
      ____ \__ \ \/ ____ \/ / __/ / __ \ \ \
      \__ \__/ / __ \__ \__/ / __ \ \ \ \/
      __/ ____ \ \ \__/ ____ \ \ \ \/ / __
     / __ \__ \ \/ ____ \__ \ \/ / __ \/ /
     \ \ \__/ / __ \__ \__/ / __ \ \ \__/
      \/ ____ \/ / __/ ____ \ \ \ \/ ____
         \__ \__/ / __ \__ \ \/ / __ \__ \
         __/ ____ \ \ \__/ / __ \/ / __/ / __
        / __ \__ \ \/ ____ \/ / __/ / __ \/ /
        \/ / __/ / __ \__ \__/ / __ \/ / __/
        __/ / __ \ \ \__/ ____ \ \ \__/ / __
       / __ \ \ \ \/ ____ \__ \ \/ ____ \/ /
       \ \ \ \/ / __ \__ \__/ / __ \__ \__/
        \/ / __ \/ / __/ ____ \ \ \__/
           \ \ \__/ / __ \__ \ \/
            \/      \ \ \__/ / __
                     \/ ____ \/ /
                        \__ \__/
                        __/

Name: Anonymous 2010-07-08 15:05

>>26
Back to twitter, please.

Name: Anonymous 2010-07-08 15:07

>>28
What makes you think I have a twatter account?

Name: Anonymous 2010-07-08 15:14

>>26
Xarn hates Penrose because of what he had to say on cognitive science. You are a poor Xarn identifier.

Name: Anonymous 2010-07-08 15:47

>>30
Hi Xarn.

Name: Anonymous 2010-07-08 16:04

>>29
You give a shit about who might be Xarn, for one.

>>30
Personally I hate what Penrose said about cognitive science, but I don't hate him for it. The bugger has managed to do enough in his own field that I have to forgive him that nonsense.

Name: Anonymous 2010-07-08 16:22

I prefer penfold

Name: /prog/ historian 2010-07-08 16:46

>>32
Caring about who may or may not be Xarn predates any prog exposure to twitter, or even picoup.

Name: Anonymous 2010-07-08 16:52

>>34
That's cool. But I happen to know that all of the Xarn fanbois/antifanbois use twitter to inform their obsession.

Name: Anonymous 2010-07-08 17:09

Yet another thread xarned. Good job!

Name: Anonymous 2010-07-08 17:11

>>30
How in the fuck does that make any sense?

Name: Anonymous 2010-07-08 17:12

>>35
Proof?

Name: Anonymous 2010-07-08 17:18

>>38
Yes, but it's only available in exchange for a copy of the current POSIX standard.

Name: Anonymous 2010-07-08 17:29


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