Update mechanism theory
I write engineering applications at work in C# .NET. Often, these applications have complex update mechanisms, at least the I end up writing complex update mechanisms.
Can anyone direct me to some books or something where I can learn update theory? Should I spend my time learning about Recursive functions? Asynchronous updates? Binary Trees? Am I even in the parking lot to get into the ballpark?
I like using properties because they seem self contained and are easy and clean to bind to the WPF and silverlight gui's that I write and I like events because it seems like it reduces spaghetti, but I don't feel like my theoretical understanding of these things is very sound.
Thanks for the help!
Here is an example of the kind of thing I'm talking about.
public delegate void ParentChangedEventHandler(object sender, EventArgs e);
public class Parent
{
List<Child> Children;
private double parentCoefficient;
public double ParentCoefficient
{
get
{
return parentCoefficient;
}
set
{
parentCoefficient = value;
ParentChanged(this, EventArgs.Empty);
}
}
public double Chaos
{
get
{
double chaos = 0;
foreach(Child child in Children)
{
chaos += child.ChildChaos;
}
return chaos;
}
}
public event ParentChangedEventHandler ParentChanged;
public Parent()
{
ParentCoefficient = 42;
Children = new List<Child>();
for (int i = 0; i < 12; i++)
{
Children.Add(new Child(this));
}
}
}
public class Child
{
public double ChildChaos;
private Parent parent;
public Child(Parent theParent)
{
parent = theParent;
parent.ParentChanged += new ParentChangedEventHandler(parent_Changed);
}
private void parent开发者_运维知识库_Changed(object sender, EventArgs e)
{
ChildChaos = 0.5 * parent.ParentCoefficient;
}
}
So, you'll notice that the child needs an update when the Parent class is changed, and then the parent needs to update when the child is changed. If I update the parent by registering it to an event in the child, it will update once for every child, when it should only update once all children have updated.
I'm sure some of you can come up with solutions to this particular problem, but please keep in mind that this is a simplified example. The real ones are much more complex.
I could really use some a book that covers the fundamental theory on this kind of thing.
It appears to me that you're talking about complex state dependencies, which can be modeled efficiently by a rules engine. A modern rules engine basically takes a set of inputs, applies a set of rules to it, some of which act again on the output of the earlier applied rules, and generate an output which conforms to those rules.
In your case, you'd have a rule which enforces the accumulation of "chaos" when the parent entity changes. This could, for example, then fire off some other rule, say, when "chaos" reaches a threshold or whatever.
Complex dependencies are managed nicely since rules are declaritive. A good rules engine that I've used experimentally is DROOLS.Net. Inrule makes a commercial one, too: http://www.inrule.com/
精彩评论