21 ms·
What are your most used design patterns?
I'm reviewing all sorts of design patterns, just to refresh my memory. What are some of the most used design patterns in the Hacker News community? Just curious. Thanks!
- fusiongyro 14y agoI 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.
- Avalaxy 14y agoService Layer, Repository, Unit of Work. Those are the first I can think of (and use very often).
- jarek-foksa 14y agoPublisher/subscriber and composite patterns had the greatest impact on the quality of my code, apps that are composited from small decoupled parts are much easier to reason about. I'm also using delegate and prototype patterns a lot, though those are rather dangerous when misused. Deep inheritance chains or excessive method overrides can easly make the code unmaintainable.
- era86 14y agois this different from the observer pattern? which languages do you program in?
- jarek-foksa 14y agoI'm not aware of the observer pattern. I'm using CoffeeScript and my implementation of pub/sub is here https://gist.github.com/4489352 https://gist.github.com/4489352 Sample usage: button = toggleOn: -> @trigger 'toggled', 'on' window = init: -> button.listen 'toggled', (buttonState) => @showWindow if buttonState is 'on'
- elclanrs 14y agoIn JavaScript I'd say I use the module pattern and prototype pattern the most.
- ulisesrmzroche 14y agoComposed Method.
- memracom 14y agoI suspect that the most used pattern in the HN community is the ActiveRecord pattern although many who use it probably are not aware that they are doing so.