I am having a configuration object in my flex3.5 application. I want that object to be unmodifiable so that no one can change any property in it once it is created.
If you're talking about a generic Object, it's impossible since it's dynamic. What you want to do is create a class that has only 'getter' functions and every property is specified in the constructor.
If you want to have it still bindable, look at my blog post about bindable read-only properties.
Use get/set methods. There is can be two strategies:
Private variables are initialized within class itself and every private variable has public get-method which makes public field read only.
If you need to set values from outside you should create set-methods and throw an error if value already set.
Related
A friend asked me this and not sure how to understand. Prolly a simple answer.
He has the following
Public Class TestClass
Public Sub Setup()
MsgBox ("Hello")
End Sub
End Class
Based on that example, what type of member is Setup, in relation to the TestClass class?
I think it it might be an instance member. Because a class is just a collection of instances (methods, properties, etc) within the class.
Correct?
This would be an instance method as opposed to a class method (static methods).
When a field, method, property, event, indexer, constructor, or destructor declaration does not include a static modifier, it declares an instance member.
More information here.
Initially my answer said that a member is the same as a field. According to the MSDN link above this was not entirely correct so I adjusted it. You'll also notice that they use the term static member instead of instance member.
Terminology is a very tricky subject and you'll notice people use many different descriptions for the same subject. This is further amplified when you take other languages in consideration and the terminology there.
It is an instance method, but not because a class is a collection of instances.
It is an instance method because TestClass is not shared (static), and must be instantiated. That is, there must be a instance of TestClass available to use its method Setup(). Conversely, with a Shared class, you do not need an instance of TestClass to use Setup(), it would be a Shared method and not an instance method.
That is academic, however, since VB does not support static classes (Shared Classes), but does support shared methods, the effective difference is that declaring Setup() as Public makes it an instance method, or declaring it as Shared would make it a static method.
When i read the doc, both seems to be the same. Then what is the difference between these two? Please explain the difference between the two with an example like in which scenario which to be used.
Regards,
The first one is a generic listener to the session. It's called whenever an attribute of any kind is being added or removed to/from a session. It's used when you want to be informed of any session attribute addition/removal.
The second one is a callback interface that can be implemented by a specific class. The callback method is called on an object implementing this interface when this object is being bound/unbound to/from the session. It's used when you want an object to be informed of its own addition/removal to/from the session.
HttpSessionBindingListener:
If an object implements HttpSessionBindingListener, it is notified when it is bound to or unbound from a session. For example,
MyObject implements HttpSessionBindingListener
{
// class definition
}
If I call
session.setAttribute ("Object", MyObject)
methods valueBound and/or valueUnbound (defined in HttpSessionBindingListener, implemented in MyObject are called)
Implementing HttpSessionBindingListener works only for the object that implements it
HttpSessionAttributeListener:
When any class implements HttpSessionAttributeListener interface it is notified when any change in the attribute list of session occurs. For example
MyClass implements HttpSessionAttributeListener
{
// implementations of methods
}
session.setAttribute ("anything", AnyObjectNotOnlyMyClass);
indicates change in the list of attributes.Implementing HttpSessionAttributeListener listens to any attribute added, removed or replaced.
If any control (e.g. a DataGrid) is cast to UIComponent, how can you get its type at runtime?
Is this possible in Actionscript?
You can use getQualifiedClassName() to get class name by the value as a string. You can use describeType() to get the full information about class. And you can use constructor property to get class itself (to instantiate new instance by existing instance). Finally you can use is operator to compare to the limited set of classes. Less recommended usage of typeof operator which is rather obsolete.
To select the right way we need to know your particular problem.
I've have a workflow whose root activity is a custom NativeActivity with a public InArgument called XmlData. When I try and use this argument in a child If activity I get the following error using XmlData within the condition:
'XmlData' is not declared. It may be inaccessible due to its protection level
My properties look like this:
public Activity Body {get;set;}
public InArgument<CustomObj> XmlData {get;set;}
and this is the CacheMetadata method:
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
var runtime = new RuntimeArgument("XmlData",typeof(CustomObj),ArgumentDirection.In,true);
metadata.Bind(this.XmlData,runtime);
metadata.AddArgument(runtime);
metadata.AddChild(Body);
}
I'm adding the argument inside CacheMetadata using the metadata.AddArgument method, and I've tried adding the child property it has using both AddChild and AddImplementationChild.
If I replace my custom activity with an ActivityBuilder and use code to create a DynamicActivityProperty then the condition can be compiled successfully, so I don't see what I'm missing when I use my own code.
There are 3 possible solutions I can think of, one is daft, one is hacky and the other vaguely sensible.
Solution 1 (the daft one)
Promote the RuntimeArgument to a private readonly member and swap the Bind and AddArgument calls around, I've had a few random occurances where this has helped.
Solution 2 (the very hacky one)
You can always put the values in a named property on the context and pull it out in the child
Solution 3 (the sensible one)
If you want to pass the InArgument to a child, bind it to a variable and bind the child to the variable.
Any of those help?
John
I apologize if that title is confusing. This question may be a result of lack of coffee and/or sleep, but my mind is not working correctly right now.
Anyways, I have an inheritance tree like so (I know the architecture isn't ideal):
BaseClass
GeneralForm : Inherits BaseClass
SpecificForm : Inherits GeneralForm
And an object like so:
MyItem
MySpecificItem : Inherits MyItem
I have Items As List (Of MyItem) as a property in BaseClass. I would like for SpecificForm to somehow override Items to return type List (Of MySpecificItem). I feel like this is easy to do, but again, my head is spinning and I can't think straight at the moment.
Thanks so much in advance.
EDIT
If the above isn't possible, is it possible to take a List (Of MyItem) and turn it into a List (Of MySpecificItem)? MySpecificItem has just one additional property that is specific to SpecificForm, but I NEED it.
Anyone? :\
You should be able in SpecificForm to just do the following...
Private pMySpecificItems As List(Of MySpecificItem)
Public Shadows ReadOnly Property Items() As List(Of MySpecificItem)
Get
Return pMySpecificItems
End Get
End Property
The 'Shadows' keyword will tell the compiler that this property in SpecificForm hides the Items property from the base-class form.
You can't actually delegate to the base class' property and "cast" it to List(Of MySpecificItem) because while a sub-class may be viewed as an instance of its base class, a base class object cannot be cast to an instance of a sub-class (as the sub-class may have added required properties/state that the base class does not support or implement).