Tag Info

Hot answers tagged

10

"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 ...


8

One of the most popular design pattern here on PO is the strategy pattern. And yes, if you build some example code around this pattern, you can demonstrate all the SOLID principles: S = is fulfilled when each strategy subclass is only responsible for exactly one task, and the "context" class does not take responsibilities which belong into the strategy ...


6

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


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 ...


6

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, ...


4

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

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

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 ...


3

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 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

The two interfaces are actually part of Reactive Extensions (Rx for short), you should use that library pretty much whenever you want to use them. The interfaces are technically in mscrolib, not in any of the Rx assemblies. I think this is to ease interoperability: this way, libraries like TPL Dataflow can provide members that work with those interfaces, ...


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 ...


2

Have you looked at Reactive Extensions? Reactive Extensions is a library that allows the composition of aysynchronous and event based code. I'd have a look at Intro To Rx, it has lots of information on when IObservable is appropriate and as J Trana has said one of the benefits is a reduction in coupling. Without more information about your application ...


2

Good question. I believe that such methods don't require its own check simply because: NullPointerException is thrown should the event occur, so assuming you tested that case at least once, you would know if null were passed. If you begin adding checks for addListener or removeListener, then you really would have to perform basic checks on every method in ...


2

First and foremost, you should be consistent with the framework convention. Java is a big world to be sure. I use Java for Android, and here the convention is rather permissive. For example, setOnClickListener allows you to pass in null - this is a crude but nonambiguous way of removing the listener. From Android source code: public class View implements ...


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

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

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 ...



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