Friday, February 26, 2010

Dynamic and Sealed Classes.

You can add programatically additional properties and methods at runtime to instances of a class if you mark that class at compile-time as dynamic. 



dynamic class Person{

}

// adding dynamically properties and methods to the object of the class
Person p = new Person();
p.name = "Ramesh";
p.age = 25;
p.printMe = function ():void {
trace (this.name, this.age);
}



the classes which are not marked as dynamic cannot have properties and methods added at runtime. Such classes are called sealed classes.Classes are sealed by default i.e. properties and methods cannot be added dynamically at runtime.

Sealed classes requires less memory as no internal has table is needed to store dynamic properties and have stricter compile-time checking as the compiler can provide better error feedback.

Reblog this post [with Zemanta]

No comments:

Post a Comment

Which is better React Native or Native iOS and Android Development for building Mobile applications ?

  React Native vs Native (iOS, Android)   Properties/Feature React Native   Native (iOS) – Swift / Object...

Labels