Re: Creating a class that is "readonly" for some classes?



You have to do it yourself. Make a check on each entrance into the object
properties.

There might be lots of ways of doing this. One way might be to make the
properties "internal" and place them in their own assembly. All classes
that need to write would be located in this assembly. Other ways might be
to wrap create another object that wraps the main object that can write to
the object, maybe using inheritance. Ultimately, you class may need at
least a reference to its parent/owner so that it can make a comparison.

Also, classes are always passed by references.

"Alex" <nospam@xxxxxxxxxxx> wrote in message
news:4389303b$0$23278$db0fefd9@xxxxxxxxxxxxxxxxx
> Hello,
>
> Is it possible to have a class that has "readonly" properties for some
> classes and can be written by others?
>
> The reason I want this is that some of my classes need to expose their
> "status", but I need to be ensure that this is only updated by the class
> that "owns" them, and is not updateable by anything else. Also, I'd rather
> these classes pass their "status" by reference instead of by value, so any
> other object querying this "status" will have an up-to-date view of the
> value.
>
> The status of the classes I mentioned is not a simple string or enum, but
> rather a more complex type, such as
>
> class Status
> {
> string Name = "N/A";
> string TypeName = "N/A";
> enState State = enState.Unknown;
> int MessagesProcessed = 0;
> etc...
> }
>
> Right now I have something like (forgive the pseudocode)...
>
> class Worker1 : WorkerBase
> {
> private Status m_Status = new Status();
>
> Worker1()
> {
> // do work - private methods will update values within "m_Status"
> object
> }
>
> public Status MyStatus
> { get { return m_Status; } }
> }
>
> I hope I'm making sense! Let me know if I need to clarify anything...
>
> Cheers,
> Alex
>


.



Relevant Pages

  • Re: another way to shoot yourself in the foot?
    ... Of course you're passing a reference, since limited types are always passed by reference (since Ada 95). ... package Wrap is ...
    (comp.lang.ada)
  • Re: testing whether an object exists
    ... This is a lot of stuff for me to wrap my brain around, ... >> If I set this object and reference at the module level, ... > Private WithEvents objXL As Excel.Application ... > Private WithEvents objWkbk As Excel.Workbook ...
    (microsoft.public.vb.general.discussion)
  • Re: VB.NET SNMP example
    ... but I can't add the reference. ... Write the code that talks to SNMP in managed C++ and wrap ... > all calls in .NET objects. ...
    (microsoft.public.win32.programmer.networks)
  • serious bug in XP that could be malicious ???
    ... Watch the line wrap in the URLs. ... >Reference the link above; is this a valid issue that a ... >SP1. ...
    (microsoft.public.windowsxp.security_admin)