tags:

views:

56

answers:

2

I've got a Registry class and there are a few Registry values that I want to access from within that Registry class. (There is a bit of a calculation with these values so I thought I'd just put all that code right in the Registry Class itself).

So we might have something within our RegistryRoutine.cls like:

Function GetMyValue() as integer
    Dim R as new RegistryRoutine

<calculations>
GetMyValue=R.GetRegisetryValue (HKEY, key, value, etc.)

End Function
+1  A: 

No, in general you won't see any problems (like member variables being overwritten or anything weird like that).

Where you could run into issues is if you have explicity shared variables that are being written to multiple times. But that's dangerous no matter what you do.

Do watch out for recursive cases - e.g., GetMyValue() should not call R.GetMyValue(), nor should GetRegistryValue() call GetMyValue().

It's rare that you actually want to do this, however.

  1. Since you're not passing any arguments into GetMyValue(), we can assume that the current instance already has all the information it needs.
  2. Since you're only returning an integer, not a RegistryRoutine instance, the client has no need for a new instance.

So, why not just call GetRegistryValue (without the R.)?

Lars Kemmann
I did consider just using the internal Procedures but I thought it'd be better to use the Class properly. E.g., to use the Class you first set the HKEY and then a the Key. I didn't want to have to figure out wether there might be sideeffects from changing a module level variable in my current instance. It *seems* like it would be safe to just create a new instance which will then have it's own private module level variable.
Clay Nichols
+1  A: 

It's quite common for classes to work with instances of themselves. Consider, for example, how a tree structure works. Either a Node class has to keep track of its children, or has to keep track of its parent (or both). All the nodes are the same class.

Scott Whitlock