|
I have implemented RM Relationship Manager for .NET using the Boo language (porting it from Python). The resulting assembly is usable from C# and other .NET languages. See C# example below.
InstallationDownload the ready to use compiled assembly (includes a sample exe) To relationship manager in your own projects just add the reference to the assembly RelationshipManager55.dll and create a RM1 instance and then make calls on it using the API below. e.g. R(), NR() etc. A full example is shown below. Source codeView the Boo source code of Relationship Manager for .NET online (color coded) on the Boo wiki page. If you want to compile it yourself then download the entire SharpDevelop project here. If you are interested in the .Net 2.0 port of relationship manager, email me. What is Relationship Manager good for?> I'd appreciate an 'how to use' example then you can ask what 'a' points to and get the result class Person: There is a bit more of a tutorial code sample in the post http://tinyurl.com/9xz5m API DocumentationThe API of the relationship manager for .NET is the new one described in RM Theory.
Basic API
Extra API
The extra API allows you to enforce relationships e.g. ER("xtoy", "onetoone", "directional") registers the relationship as being one to many and directional, so that e.g. when you add a second relationship between the same two objects the first relationship is automatically removed - ensuring the relationship is always one to one. Alternatively, you could raise and exception. The extra API also adds a pair of find methods that only find one object, and cast it to the appropriate type. This is a commonly used convenience method. UML class diagram for the .NET relationship manager implementation. Templates for useI recommend you look at the templates for what relationship manager API calls to make in order to model any relationship pattern you want. For example, to implement a one to many relationship between two classes X and Y, you might use the following template:
Thus if you have a class called Customer and a class called Order, then the Customer class would correspond to class X and the Order class to class Y. Your methods might be AddOrder(o) which corresponds in the above example to addY(y). Its up to you to rename both the class and method names of the template to match your own classes. A concrete exampleSay you want to model a Person class which has one or more Orders. The Orders class has a backpointer back to the Person owning it. Instead of hand coding and reinventing techniques for doing all the AddOrder() methods and GetOrders() methods etc. using ArrayLists and whatever, we can do it using the relationship manager object instead, which turns out to be simpler and faster and less error prone.The RM (relationship manager) is implemented in this particular example as a static member of the base BO (business object) class. Thus in this situation all business objects will be using the same relationship manager. Here is the c# code to implement the above UML: usingSystem; using System.Collections; using RelationshipManager55; namespace WindowsApplicationUsing_RelationshipManagerDllTest001 { /// <summary> /// BO is the base Business Object class which holds a single static reference /// to a relationship manager. This one relationship manager is /// used for managing all the relationships between Business Objects. /// </summary> public class BO // Base business object { static protected RM1 RM = new RM1(); } /// <summary> /// Person class points to one or more orders. /// Implemented using a relationship manager rather /// than via pointers and arraylists etc. /// </summary> public class Person : BO { public string name; static Person() { RM.ER("p->o", "onetomany", "bidirectional"); } public Person(string name) { this.name = name; } public override string ToString() { return "Person: " + this.name; } public void AddOrder(Order o) { RM.R(this, o, "p->o"); } public void RemoveOrder(Order o) { RM.NR(this, o, "p->o"); } public IList GetOrders() { return RM.PS(this, "p->o"); } } /// <summary> /// Order class points back to the person holding the order. /// Implemented using a relationship manager rather /// than via pointers and arraylists etc. /// </summary> public class Order : BO { public string description; public Order(string description) { this.description = description; } public override string ToString() { return "Order Description: " + this.description; } public void SetPerson(Person p) { RM.R(p, this, "p->o"); // though mapping is bidirectional, there is still a primary relationship direction! } public Person GetPerson() { return (Person) RM.P(this, "p->o"); } public void ClearPerson() { RM.NR(this, this.GetPerson(), "p->o"); } } } Here is the project source code WindowsApplicationUsing RelationshipManagerDllTest001.rar Feedback?Contact abulka@netspace.net.au See alsoThe original design pattern RM Relationship Manager |