publically readonly but internally writable objects?
-
I was wondering if somehow it is possible to make objects readonly if referenced by another assembly but writeable when accessed internally? For example I have a scenario where I need to pass objects to UI. UI must not be allowed to temper with the object in any form or fashion but the business layer should have full access to the object as we need to do some computation after the object is inialized by the DAL. I was just wondering if there is a preferred way of dealing with situations like these that I am not aware of? Would appreciate the help ... Thanks in advance.
-
I was wondering if somehow it is possible to make objects readonly if referenced by another assembly but writeable when accessed internally? For example I have a scenario where I need to pass objects to UI. UI must not be allowed to temper with the object in any form or fashion but the business layer should have full access to the object as we need to do some computation after the object is inialized by the DAL. I was just wondering if there is a preferred way of dealing with situations like these that I am not aware of? Would appreciate the help ... Thanks in advance.
-
I was wondering if somehow it is possible to make objects readonly if referenced by another assembly but writeable when accessed internally? For example I have a scenario where I need to pass objects to UI. UI must not be allowed to temper with the object in any form or fashion but the business layer should have full access to the object as we need to do some computation after the object is inialized by the DAL. I was just wondering if there is a preferred way of dealing with situations like these that I am not aware of? Would appreciate the help ... Thanks in advance.
student_rhr wrote:
I was just wondering if there is a preferred way of dealing with situations like these
There are three ways (that I know of... :)): 1. Create an interface that only declares the elements (e.g. property getters) that the UI should see. 'Implement' it on the class of interest (actually you only have to declare it). Then pass this interface around instead of the 'real' object. 2. Implement the Data Transfer Object design pattern to handle the situation. It is described here^. In short, this method declares a struct or immutable class with all the data of interest, and if you have to pass around these data you create such an object (with a copy of the relevant data) for this purpose. 3. Declare the objects property setters and methods (if they are able to change the objects state) as internal, everything else as public. 'Internal' means exactly that: Public for everything inside the same assembly, invisible for everything outside. What best suits your needs depends on your overall architecture and the situation... Hope this helps. Regards Thomas
www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software. -
I was wondering if somehow it is possible to make objects readonly if referenced by another assembly but writeable when accessed internally? For example I have a scenario where I need to pass objects to UI. UI must not be allowed to temper with the object in any form or fashion but the business layer should have full access to the object as we need to do some computation after the object is inialized by the DAL. I was just wondering if there is a preferred way of dealing with situations like these that I am not aware of? Would appreciate the help ... Thanks in advance.