Class Design Help
-
We have a client driven app, each client has a number of delegates. We are designing a system to manage these and are currently trying to work out the objects. A client has many delegates, and so should the client object contain a list of these delegates? If so that means that when an client is loaded from the database each of the delegate objects would also be loaded (is this too tightly coupled? There could be 100s of delegates associated with any given client) The reason that the delegate need to be associated with the client is that, when the client is loaded the associated delegates need to be displayed with basic read only information (this information is unknown at the minute, but will include name, email, phone etc). On the other hand if a delegate is loaded then, basic read only client information needs to be displayed on the delegate record. If we then referenced the client from the delegate, this would cause a loop of reference meaning that if you load a delegate or client all associated delegates would be loaded. Any suggestions of a class design or design pattern? I feel that others must have done this?
-
We have a client driven app, each client has a number of delegates. We are designing a system to manage these and are currently trying to work out the objects. A client has many delegates, and so should the client object contain a list of these delegates? If so that means that when an client is loaded from the database each of the delegate objects would also be loaded (is this too tightly coupled? There could be 100s of delegates associated with any given client) The reason that the delegate need to be associated with the client is that, when the client is loaded the associated delegates need to be displayed with basic read only information (this information is unknown at the minute, but will include name, email, phone etc). On the other hand if a delegate is loaded then, basic read only client information needs to be displayed on the delegate record. If we then referenced the client from the delegate, this would cause a loop of reference meaning that if you load a delegate or client all associated delegates would be loaded. Any suggestions of a class design or design pattern? I feel that others must have done this?
Its hard to understand your question, because both the word "client" and "delegate" have lots of meanings. But I think I understand. You have a master-detail (one-to-many) relationship between clients and delegates, and you want to have a client object with a property that contains a collection of delegate objects. Each delegate object will have a property reference back to a client object. The simple solution is to use lazy-load properties. (Have the necessary properties, but only instantiate the actual objects the first time the properties are used). This prevents the "loop" scenario you mention. If it is a small .NET app, then you could consider using Castle ActiveRecord, which will do this for you. (Or any OR-Mapper will also do it).
-
Its hard to understand your question, because both the word "client" and "delegate" have lots of meanings. But I think I understand. You have a master-detail (one-to-many) relationship between clients and delegates, and you want to have a client object with a property that contains a collection of delegate objects. Each delegate object will have a property reference back to a client object. The simple solution is to use lazy-load properties. (Have the necessary properties, but only instantiate the actual objects the first time the properties are used). This prevents the "loop" scenario you mention. If it is a small .NET app, then you could consider using Castle ActiveRecord, which will do this for you. (Or any OR-Mapper will also do it).
Many Thanks for your reply :) I think you understand my problem! using lazy-load properties would be ok, but.. I will have a screen showing client information (ie, linked to an instnace of a client class), on this screen i need to show basic information about each delegate at that client (say in a datagridview, and when they click on a delegate it opens a delegate screen), so i would end up loading each delegate anyway. The only way i can think of doing this is to have a cut down delegate class that is used for displaying on the client screen and then if that client is selected to be loaded, create a full delegate instance. I just worry that this could result in loads of different types of cut down delegate classes, if a delegate summary needs to be shown on any other forms