design-patterns

nodejs auto refresh view after database updates

不打扰是莪最后的温柔 提交于 2021-01-20 16:56:42
问题 I would like use nodeJS to refresh my view, every time a function has made changes to the database. If we take MEAN-stack as an example, I don't want to send an $http-request every x seconds to check if changes have been made to the database. I would like the front end to get notified automatically and then update the view. What are best practices for this? I would use some kind of Oberserver pattern in the server side, but do not know how I could notify the front end with that. 回答1: To get

When do I keep a map<Identifier, Object> vs a Collection<Object with identifier as field>

不羁岁月 提交于 2021-01-08 02:04:15
问题 There is one question that I often ask myself while designing a program, and I am never quite sure how to answer it. Let's say I have an object with multiple fields, amongst which there is one serving as the identifier to that specific object. Let's also say that I need to keep track of a List of such objects somewhere else. I now have three, and probably even more, options on how to go about it: Have my object contain its own identifier, and all its other fields. I now use a simple array (or

When do I keep a map<Identifier, Object> vs a Collection<Object with identifier as field>

回眸只為那壹抹淺笑 提交于 2021-01-08 02:01:27
问题 There is one question that I often ask myself while designing a program, and I am never quite sure how to answer it. Let's say I have an object with multiple fields, amongst which there is one serving as the identifier to that specific object. Let's also say that I need to keep track of a List of such objects somewhere else. I now have three, and probably even more, options on how to go about it: Have my object contain its own identifier, and all its other fields. I now use a simple array (or

When do I keep a map<Identifier, Object> vs a Collection<Object with identifier as field>

ε祈祈猫儿з 提交于 2021-01-08 02:01:24
问题 There is one question that I often ask myself while designing a program, and I am never quite sure how to answer it. Let's say I have an object with multiple fields, amongst which there is one serving as the identifier to that specific object. Let's also say that I need to keep track of a List of such objects somewhere else. I now have three, and probably even more, options on how to go about it: Have my object contain its own identifier, and all its other fields. I now use a simple array (or

When do I keep a map<Identifier, Object> vs a Collection<Object with identifier as field>

懵懂的女人 提交于 2021-01-08 02:01:15
问题 There is one question that I often ask myself while designing a program, and I am never quite sure how to answer it. Let's say I have an object with multiple fields, amongst which there is one serving as the identifier to that specific object. Let's also say that I need to keep track of a List of such objects somewhere else. I now have three, and probably even more, options on how to go about it: Have my object contain its own identifier, and all its other fields. I now use a simple array (or

How can I build a nested list using builder pattern?

a 夏天 提交于 2021-01-07 06:50:29
问题 I am trying to make a query builder for GraphQL syntax, by using a builder pattern. I already did it for the filtering part: I want to programatically make a way to say what data I want to get back from the query. (NOTE: before the title part of the query was hardcoded into the QueryBuilder. So for that I made a class called Entity which has a list of itself as an attribute. class Entity( private val entity: EntityType, private val entities: MutableList<Entity> = mutableListOf() ) { override

Order of decorations in Decorator Pattern

徘徊边缘 提交于 2020-12-29 09:46:11
问题 Most of you know the pizza / cofee example for the decorator pattern. Pizza* pizza1 = BigPizzaDecorator(MushromDecorator(SimplePizza())); Pizza* pizza2 = MushromDecorator(BigPizzaDecorator(SimplePizza())); the two object behave in a similar way, but not completely, in particular if you have non-commutative operation, for example: BigPizzaDecorator::price() { return 10 + PizzaDecorator::price(); } // this is commutative BigPizzaDecorator::name() { return "big " + PizzaDecorator::name(); } //

C++ templated class implementation of the multiton pattern

拥有回忆 提交于 2020-12-29 07:53:50
问题 I implemented the multiton pattern using a templated class in C++. #ifndef MULTITON_H #define MULTITON_H #include <map> template <typename Key, typename T> class Multiton { public: static void destroy() { for (typename std::map<Key, T*>::iterator it = instances.begin(); it != instances.end(); ++it) { delete (*it).second; } } static T& getRef(const Key& key) { typename std::map<Key, T*>::iterator it = instances.find(key); if (it != instances.end()) { return *(T*)(it->second); } T* instance =

Whats the best practice for creating Stateless Utility classes in Java [closed]

让人想犯罪 __ 提交于 2020-12-28 15:01:10
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . Improve this question What's the best practice for creating the Utility (which do not hold any state) classes in Java. In most of the cases we end up creating static methods for such tasks. Other possible way could be "create the singleton objects" for performing this

Whats the best practice for creating Stateless Utility classes in Java [closed]

大憨熊 提交于 2020-12-28 14:58:34
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . Improve this question What's the best practice for creating the Utility (which do not hold any state) classes in Java. In most of the cases we end up creating static methods for such tasks. Other possible way could be "create the singleton objects" for performing this