Tag Info

Hot answers tagged

6

Not sure what you mean with reference driven programming. From what I gather, you're wondering what the advantages of event-driven programming are as opposed to writing code, and then using a bunch of branches to determine when to call a given method. Before I set off, allow me to be pedantic and point out that: a module can't listen for any event, nor can ...


5

Promises were made to solve problems like this; they work really well in functional languages (I've personally used them extensively in Javascript, where curiously jQuery actually has the worst implementation of them - see this comparison). The weird thing about using promises is accepting that things are easier when you make everything use them. I will ...


4

There's a third option: mock the object with the event and use behavior testing to verify the mock's subscriptions at given points. Several mocking frameworks allow for this. public interface INeedToBeMocked { public event EventHandler EventRaised; } NSubstitute var mockedItem = Substitute.For<INeedToBeMocked>(); ...


3

Yes, I believe your assumption is correct. I also tried to write some (ugly) code to test this hypothesis: class MyClassWithEvent { public event Action Fired; void OnFired() { var d = Fired; if (d != null) d(); } } class MyClassSubscribing { void M() { } public void DoSubscribe(MyClassWithEvent mcwe) { mcwe.Fired += M; ...


3

Not 100% sure I know what you're asking. But, I get the sense you're at a point where event-driven programming doesn't feel "real" enough -- or like you're at the mercy of someone else's event system. Or like your application isn't really "doing" anything. Or like it's just a bunch of disparate methods that you're feeding another application. So. Suppose a ...


2

Is there a better way to solve this problem? Yes! C# allows you to override the += and -= syntax. I'm not sure how easy it is to supply in common mocking frameworks like Moq, but it should be trivial to build your own fake object that has hooks into the subscribe and unsubscribe methods of your interface: private Action foo = () => {}; ...


2

When sending messages/events across a system, you should use specialized data messages for the payload. If not, if for example your user class changes, everything that listens to messages that have a user as payload, could be affected by that change as well. As to your question about normalizing: it's not because the signals share the same payload now, ...


1

What you are describing is a common issue in reactive programming. The idiom is for asynchronous code to produce a Future which acts as a rendezvous point for other code. The code that depends on the results uses call-backs (or call-forwards, depending on your point of view), which take the value as it will be produced in the future. With suitable language ...


1

Why shouldn't event listeners outlive the object that registered them? It seems like you are assuming event listeners should registered by methods of controls(if we take the GUI example) - or more precisely, methods by objects of classes that inherit the GUI toolkit's controls. That's not a necessity - you could, for example, use a specialized object for ...


1

There is a subtle, but important difference between commands and events. A command has a presumption of a response whereas an event does not presume a response, it's merely a statement. To be less abstract: ShipOrder is a command and the sender of ShipOrder will likely expect a response of some sort. OrderShipped is a declaration and the sender is ...



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