Design question
-
These are the requirements: Assembly ‘Shared’ defines class named ‘SharedClass’ . SharedClass contains field named ‘Info’. Assembly ‘Runtime’ defines class named ‘Manager’ ‘Manager’ should be allowed to read and change field ‘Info’ on the instance of SharedClass. Assembly ‘GUI’ defines class named ‘Client’. ‘Client’ can only read from field ‘Info’. Can somebody help outline design that supports such requirements. Thanks in advance, Elina
-
These are the requirements: Assembly ‘Shared’ defines class named ‘SharedClass’ . SharedClass contains field named ‘Info’. Assembly ‘Runtime’ defines class named ‘Manager’ ‘Manager’ should be allowed to read and change field ‘Info’ on the instance of SharedClass. Assembly ‘GUI’ defines class named ‘Client’. ‘Client’ can only read from field ‘Info’. Can somebody help outline design that supports such requirements. Thanks in advance, Elina
I tried writing an answer for this, but there are still some missing pieces. For example does Runtime own SharedClass or is SharedClass a static class that is visible to both Manager and Client? You did not say but imply that SharedClass is an instance class so someone must contain it. Then there is the way it is accessed. If you have a containing class and expose a method to do the read/update, you can alway incorporate a Context class that each caller would implement. The context would help the setter in SharedClass determine if the update is allowed in the given Context. One possibility: SharedClass exposes GetInstance(Context context) context is fed to the instance which is used to determine if the setter should be active. Another possibility: SharedClass is static and the access to info is exposed: public static bool UpdateInfo( object info, ContextClass context ) context contains the AssemblyName of the caller.
-
These are the requirements: Assembly ‘Shared’ defines class named ‘SharedClass’ . SharedClass contains field named ‘Info’. Assembly ‘Runtime’ defines class named ‘Manager’ ‘Manager’ should be allowed to read and change field ‘Info’ on the instance of SharedClass. Assembly ‘GUI’ defines class named ‘Client’. ‘Client’ can only read from field ‘Info’. Can somebody help outline design that supports such requirements. Thanks in advance, Elina
You can use InternalsVisibleToAttribute to supply access to internal members of assembly A to members od asembly B.
//Inside Shared Assembly
[assembly:InternalsVisibleTo("Runtime")]public class SharedClass
{
private string info;public string Info
{
get
{
return info;
}
}internal void SetInfo(string info)
{
this.info = info;
}
}Manager defined by Runtime has access to SetInfo and calls it to modify info.
-
These are the requirements: Assembly ‘Shared’ defines class named ‘SharedClass’ . SharedClass contains field named ‘Info’. Assembly ‘Runtime’ defines class named ‘Manager’ ‘Manager’ should be allowed to read and change field ‘Info’ on the instance of SharedClass. Assembly ‘GUI’ defines class named ‘Client’. ‘Client’ can only read from field ‘Info’. Can somebody help outline design that supports such requirements. Thanks in advance, Elina
Sounds like Model View Controller (or "shared gui manager" if you will) pattern... You'll have three projects 1. Shared project for model classes like SharedClass 2. Runtime project references Shared project so Manager has access to SharedClass 3. GUI project references Runtime and Shared project so Client can access SharedClass and Manager (though your requirments don't mention Manager access, it's part of MVC). So your view and your controller can see and use your model, and your view can also use your controller to act on the model. I'll leave it to you to decide how to restrict Client's write access. Visit BoneSoft.com