Click here to Skip to main content
15,035,600 members
Articles / Programming Languages / C#
Technical Blog
Posted 9 Jan 2012

Tagged as


7 bookmarked

Adapt to Changes With Dynamic Behaviors

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
15 Feb 2012CPOL4 min read
Discuss adding functionality at runtime using Component-Based Object Extender with static typing

Requirements are moving targets. It is hard for a static programming language to keep up with changes of requirements of a software system. Interestingly, we have seen increasing efforts to make C# programming language more dynamic with dynamic keyword in C# and ExpandoObject type in .NET 4.0.

With Component-Based Object Extender (CBO Extender), an object extensibility framework for .NET, behaviors can be added to object at runtime. It makes a software system more flexible and adaptive to changes.

Static Typing, Dynamic Typing and Dynamic Behaviors

Static typing is class-based programming in which a class has to be defined at design time prior to an object can be created out of it and used. In class design, methods are molded into classes, which is both a blessing and curse. On the brighter side, molding methods into classes is at the core of objects being able to receive messages and the ability to define standard protocols. On the darker side, explicitly molding every single method to a specific class leads to programs that are rigid and hard to evolve and maintain. Static typing is facing serious challenges from today’s constantly changing business requirements while software systems are continuously getting bigger and more complicate.

Dynamic typing is prototype-based programming in which classes are not present, and behavior reuse is performed via a process of cloning existing objects that serve as prototypes. With dynamic typing, you can add, delete or alter methods of an object at runtime anywhere in a program. It is so flexible that it is hard to maintain correctness, safety and predictability in a large software system. It does not seem to be a good solution to the challenges that static typing is facing.

Then, how can we make the class-based programming more dynamic without sacrificing its strengths? Well, if you think about the dynamic typing a bit more, you will find ultimately what we need from dynamic typing is its ability to add behaviors at runtime (dynamic behaviors). However, it does not mean that dynamic behaviors can only be provided by dynamic typing. Proxy-based programming can, too, add behaviors at runtime by decorating methods of object. In proxy-based programming, a dynamic decorator is used to attach behaviors to an object and returns a proxy of the object. To client of the object, the proxy is still the same type and is used as if it was the original object.

Proxy-based programming complements class-based programming with dynamic behaviors, which makes a software system more flexible and readily adaptive to changes without involving dynamic typing. With class-based programming, an application developer can expect a software component with core business functionality and well-defined client contract (interfaces). With proxy-based programming, the application developer can add extra functionality to objects of the component as needed at runtime.

Dynamic Behaviors with CBO Extender

Perhaps, one of most important accomplishments coming out of class-based programming is the concept of interface (client contract). With interface, a client does not need to know about the inner workings of a component in order to make use of it. By programming to interface, the client is completely decoupled from the implementation of a component. Consequently, a component can replace another (at design time or runtime) as long as the successor component implements the same interface as the initial component without breaking the system in which the component operates.

CBO Extender is proxy-based and uses programming to interface. With CBO Extender, you define a set of aspect methods to represent behaviors based on your business or system requirements. These behaviors, then, can be used to decorate object’s methods as needed in your application using its Dynamic Decorator or AOP Container.

CBO Extender works directly with objects and interfaces. It does not know or care, and is completely decoupled from, the classes from which objects are created. Any interface methods can be decorated with extra behaviors at runtime. Cross-cutting concerns like logging, security checking or transaction management can be presented as dynamic behaviors which are added to objects at runtime as needed (see article Dynamic Object Programming for examples). Business requirements like sorting or anything (e.g., Hello World!) can also be presented as dynamic behaviors which are added to objects at runtime (see articles Application Development With Component-Based Object Extender and OOP, AOP and OP).


  • Mixing static typing with dynamic typing does not solve the rigidity associated with class-based programming.
  • Proxy-based programming complements class-based programming with dynamic behaviors.
  • Dynamic behaviors make software system flexible and adaptive to changes.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Gary H Guo
United States United States
Object-oriented (OO) is about "classes" not "objects". But I truly believe that "objects" deserve more our attentions. If you agree, read more on... Dynamic Object Programming (DOP), Component-Based Object Extender (CBO Extender), AOP Container and Dynamic Decorator Pattern.

Mobile development is not just another type of front end. The real challenge is actually in the back end: How to present meaningful information in time to mobile users with exponentially increased data flooding around? Here is my first mobile solution: SmartBars - Barcode Reader, Price Comparison and Coupons.

Gary lives in southeast Michigan. My first programming language is FORTRAN. For the last a few years, I have primarily focused on .NET technologies with Mobile Development as my newest interest.

Comments and Discussions

Questioncomparison table Pin
Gil.Schmidt15-Feb-12 21:14
MemberGil.Schmidt15-Feb-12 21:14 
AnswerRe: comparison table Pin
Gary H Guo16-Feb-12 3:31
MemberGary H Guo16-Feb-12 3:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.