Today’s development notes
I did two things with EcoGillespie development today:
- Renamed the
IndividualclassNode, to reflect that it’s the superclass for anything that can be a node in a network. - Wrote a temporary
main()function in theDiseaseNetworkexample that actually instantiates an object. - That is, three things. I also actually tested the code that I had written so far, finding that there was a problem with the parameter-setting code (see below).
One cool thing that’s in this code that I forgot to mention in the earlier post:
Automatic parameter setting Cocoa has this fancy thing called key-value coding that lets you set properties on objects without a compile-time binding to a setter method. You just say [object setValue:someValue forKey:@"someKey"] and Cocoa automatically does the rest. This naturally extends to things like [object takeValuesFromDictionary:dict], letting you set a whole bunch of values in one go.
Seems like a perfect match for setting parameters on model objects. Too bad Java doesn’t have it. If Java had support for categories like Objective-C, I could have just added a category to Object to provide this . This isn’t the case, so instead I added methods to the ParameterMap class to do this: void applyAllParameters(Object) and void applyParameter(String, Object). They use the Java reflection API to look up the appropriate setter method and call it with the value set in the parameter map. This means that, as long as the model object inherits Model’s constructor implementation, parameters will get set automatically.
Finally, something I plan to start soon:
Unit testing I’ve never been conscientious about doing this before. My first public API seems like a good place to start. I want this code to be very strong.