3 ms·
I get a lot of mileage out of the delegate pattern. We used visitor exactly once in our codebase, but it's pretty fantastic for that one place it's needed. We u
by fusiongyro 14y ago
I get a lot of mileage out of the delegate pattern. We used visitor exactly once in our codebase, but it's pretty fantastic for that one place it's needed. We use observer extensively. More than other patterns that one strikes me as something the language should do for me.
- era86 14y agowhat 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.