You can see how DependancyObject (s) and DependanceProperty (s) work in WPF / Silverlight.
Here is an example of how it works in WPF / Silverlight for class "A" with the "Foo" property with a default value of 5.
class A : DependancyObject { static DependancyProperty PropertyFoo = DependanceProperty.Register( "Foo", typeof(int), typeof(A), new PropertyMetadata( 5 ) ); int Foo { get { return (int)GetValue( PropertyFoo ); } set { SetValue( PropertyFoo, value ); } }
The downside is that you have to "manually" implement your properties, you cannot use the simple syntax "int Foo {get; set;}", but code snippets can help a bit.
Obviously, if you do not want to use WPF or Silverlight, you will have to implement all this yourself, but you will get the following benefits.
Since DependancyProperties are objects, they can retain their default value, which can be used by any DependancyObject that has not overridden the value.
DependancyObjects only maintains a list of values if the value is changed, so objects that are the same as the default do not use additional memory.
Since the entire set of properties passes through DependancyObject.SetValue, it is easy to implement logic in one place in order to make certain properties or entire objects readonly.
There are other advantages / features that you can add as animating properties, etc., but if you have implemented it, you can save it as simple / complex as you like.
source share