Applying Decorator To Control Menus

This article of mine on code project talks about one of the applications of Decorator pattern. Any GUI based application that are menu driven would have some logic to turn on / off the menu items based on different set of attributes like ( Licensing policies, user roles, application state etc ). Decorator comes handy on keeping this implementation extensible and maintainable. Here is the link to the article. Happy reading!

http://www.codeproject.com/KB/architecture/MenuStateHandling.aspx

Advertisements

2 thoughts on “Applying Decorator To Control Menus

  1. Krishnan,

    I happened to glance thru your article, its a good usage of bits technique.

    I have couple of questions on them
    1. Does bits implementation has a limitation with respect to number of representations it can hold?
    2. How to delineate a need for configuration of user role and not embed in code directly?

    I understand the intent of the article, however my observations overall are
    1. Strong dependency on Enums
    2. Good scope for loose couple excercise

    I liked your style of expressing thought to idea to code.

    Tenali

    • Thanks for reading thru and sharing your feedback.

      Here are my response to your questions.

      1. The Bit value finally is stored on an Int32. So technically speaking the limitation is the max value that an Int32 can hold.
      2. I had embedded the user role evaluation for illustration. The UserPolicy decorator, can look up a Database / AD / FileSystem to load / evaluate user policies.
      3. You can remove the Enum dependency by having an List. But Enum has always been my preferred choice in my programs. I use it a lot due to its compile time type safety and its ability to reduce in looping logic.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s