Tag Info

Hot answers tagged

9

"It depends" Compiler directives can be exceptionally useful tools. They can provide ironclad rules that keep development (debug) acceptable aspects out of production (release) builds. Likewise, an assembly can be made more lightweight by removing tracing instructions once the build is switched to release. On the other hand, they can be abused. I once ...


6

There is no delegate pattern per se. I am going to assume you mean Delegation Pattern. As I understand it, they're the complete reverse of each other and used for different purposes. Generally, with an Observer Pattern, any number of observer objects will listen to an event on a second object and act on the event. The second object has no knowledge of its ...


5

Logging is usually implemented with the Chain of responsibility pattern pattern. Of course you can (and I would) combine that with a Facade. I really wouldn't use Listener(s) or Observer(s) myself.


5

I think you're taking this from a backwards approach. Anti-patterns are a way of naming things that are known to have bad characteristics - they are diseases, not symptoms. It's really the symptoms we care about, even if we haven't named this specific disease yet. The way you should be talking about this is in terms of actual functional defects or deficits ...


5

Your idea was already invented 10 years ago by Herb Sutter. See this article: http://www.drdobbs.com/cpp/generalizing-observer/184403873, it contains a full explanation. So the answer is yes, it is an improvement over the original GOF variant of the pattern no, it is not better than every other known implementation of the Observer pattern Also note ...


5

By using the observer pattern, A needs not know about B or C. If you explicitly had A call B and C then it would necessarily know about B and C. Depending on how you do it, B and C don't even know about A, some D ties them all together. That "lack of knowledge" is at the core of decoupling components.


4

An alternative would be as follows. Observers are notified of the event through the method // Method on all observers. void notify(Event event) All new objects are subscribed to the notification, so the subject, instead of if (subject.eventAlreadyHappened()) { observer.executeStuff(); } else { subject.subscribe(observer); } does simply ...


4

You're looking at things incorrectly. An observer sees that a particular event occurs. It does not impact it, or own it. A delegate handles a particular event, and has ownership of the handler, even if the delegator owns the interface to the event.


4

Whether C++ or JAVA, a Notification to the observer can come along with the information of what is changed. The same methods notifyObservers(Object arg) can also be used in C++ as well. Generally, the issue will remain is that there could be multiple subjects dispatching to one or multiple observers and hence, the class arg cannot be hard coded. Usually, ...


3

Your design doesn't really violate the Observer pattern, because the pattern does not specify how subscribers get registered with the publisher. But you are violating the Single Responsibility Principle for those middle panels, because they are given the added responsibility of helping in getting the message tray subscribed. A better design would be to use ...


3

You could solve this issue by making Point an immutable object. Immutable objects are objects with read-only properties which are set at creation and can not change during the lifetime of the object. This might seem limiting at first, but it greatly simplifies code because you have less effect-at-a-distance. When you need to change a position, you would ...


3

Microsoft Access(2010+) have data macros which are like triggers, but I don't think they run unless an Access application is running or if an ODBC connection can recognize them. You may not have the ability to add these. It's not too much to have a service pole the database. As far as your performance concerns, the frequency may need to be less than you ...


3

The logic is riddled with compiler directives that change it's internal behavior based on which .Net project it happens to be compiled in. Compiler directives aren't the problem, they're just the means used to create the alleged problem. You'd probably have the same objection if you had to comment out and uncomment various blocks of code based on ...


3

You should use some kind of ajax push (see Comet) to notify the clients. It can eliminate the need for polling, you basically keep an established connection open which can be used to notify the browser of ocurring events. However, this does not work with all browsers. You fall back to "long polling" in such cases.


3

The idea of the Observer pattern is to allow an object to register for updates from another object, without the other object having to know about the actual type of the observer. In statically typed languages such as Java or C++, this is done by having the class of the object that needs to register for updates, inherit from the Observer class or implement ...


2

I think this is the kind of reason WenbSockets were created for. If you don't need compatibility with older browsers you might want to use this instead of polling. You should probably use polling as a fallback anyway. http://www.w3.org/TR/websockets/ I'm not sure how stable the spec/implementations are these days (it was not very stable not so long ago). ...


2

That's a question of several trade-offs. Trade-offs: flexibility (in terms of having n > 1 delegates/observers) cost of sending a message resilience (ability to sustain unavailability of delegate/observers) ease of use Delegate pattern: not very flexible - adding more than 1 delegate is not possible (implies some form of "multi-delegate" i.e. ...


2

I'm not sure it is an anti-pattern as such but it would seem to violate the SRP. But that being said, there were probably perfectly good reasons the developer did what they did at the time. Despite the great strides made in design patterns and various methodologies, software entropy will continue to be an unfortunate feature of legacy systems. I'd be ...


2

Sure, these things exist. D-BUS comes to mind, or any number of messaging frameworks (RabbitMQ , AMQP, ZeroMQ, etc). They're all variations on a similar theme. Increased latency compared to directly-connected peers, and increased complexity for complex topologies. The biggest one I can think of is the ability to extend to multiple WANs and scale to massive ...


2

I can try to answer your question on a generic level. You can create a centralized repository object which contains all currently loaded matrix objects and also records accesses to them. It loads the matrix objects on first access and stores them internally. All requests for these matrix objects must go through this repository object to record them ...


1

Assuming you did make the Observer class just another standard class and created a new instance, what would you intend to do with it then? An observer without any behavior is a rather useless object. Any logic specific to what you are observing would end up in a subclass anyways (i.e. MyEventObserver) and anything that would be generic enough to be used by ...


1

There are two possibilities: Pass the "message tray" to whatever component needs it Make each component that can have controls implement the "tray" interface. That way, the holder of the internal panels is also a tray and it can dispatch the messages to it's parent tray (if any). I like more #2 because it allows you to be more flexible in how the ...


1

If you wanted to simplify the nitty gritty implementation details into a class called TelnetConnection, I definitely think that would be a wise idea, however it may be that you cannot do it with simply one class. You may need to have a secondary class which deals with the asynchronous aspect of this. Lets call this class TelnetObserver which implements ...


1

Is it correct that only one ServerSocket may bind to a Port? I take it there's no way to have a pool of objects accepting Socket connections? Correct. Only one thing can bind to a particular port on a given network interface at a time. Whenever a connection is received, a new socket is automatically created for the client on a deferred/internally-routed ...


1

Acess will let you use linked tables to tables in another db especially SQL server. Is it possible to migrate your data to such? Then you can use triggers or jobs to do the montioring you need.


1

The delegate pattern, as I understand you, is know as the event handler mechanism in other languages, for example Delphi. As such it simply is an implementation of the observer pattern with a major restriction: only one listener at a time. The disadvantage of event handlers or delegates is obvious: only one observer. The advantage is not so obvious: ...


1

Just to check, you do know that your Functor is just std::function, right? Secondly, it absolutely is better. You can register lambdas, function objects, etc, so it's far more flexible than requiring derivation, and you don't have to define ten billion interfaces, all of which are dupes of each other.


1

That's called Reactive Programming. Look at Rx. Rx is all about this. It treats observables as enumerables and then what you are doing becomes as simple as calling map on the first sequence of events. events.map(new function(each) { return override != null ? override : each } Rx is available for many languages, you'll find a video with an introduction ...


1

This is why creational patterns exist, often times creation of types can be tricky as you have run into. I think you want an abstract factory here (caveat: not true if user control A/B/C have basically identical attributes, if they're identical you just need a single method that will create a control with the desired configuration which can be treated as ...



Only top voted, non community-wiki answers of a minimum length are eligible