3 ms·
what kind of code is this? C#? Java? im looking into the delegate pattern and it seems to be something C# and Java devs like to "talk" about
by era86 14y ago
what kind of code is this? C#? Java? im looking into the delegate pattern and it seems to be something C# and Java devs like to "talk" about
- fusiongyro 14y agoI'm doing Java at work, but I use delegation a lot in all OO languages. For instance, today I wrote some code in a managed bean that handles access control. My requirements have stipulated that users fall into three categories and they have different sets of rights. So I made an enum for the three categories which provides methods for each of the rights, and my access control bean delegates to the enum. This way when management decides to relax the restrictions around these users I can delete the enum for these categories and change the delegate methods to just return true or false and none of the callers will be the wiser. I'm protecting the user's-category information from leaking into the rest of the system while allowing the ramifications of the choice in through the appropriate gateway.