Dynamically add properties to a existing object

后端 未结 7 1311
说谎
说谎 2020-12-01 13:49

I create the person object like this.

 Person person=new Person(\"Sam\",\"Lewis\") 

It has properties like this.

person.Dob         


        
7条回答
  •  抹茶落季
    2020-12-01 14:24

    Consider using the decorator pattern http://en.wikipedia.org/wiki/Decorator_pattern

    You can change the decorator at runtime with one that has different properties when an event occurs.

提交回复
热议问题