Created
December 3, 2012 18:56
-
-
Save onyxmueller/4197104 to your computer and use it in GitHub Desktop.
Otto event failures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Version 1: | |
package com.example.otto.sample; | |
public class SomeKindOfEvent { | |
public final boolean wasSuccess; | |
public final EventData eventData; | |
SomeKindOfEvent(boolean success, EventData eventData) { | |
this.wasSuccess = success; | |
this.eventData = eventData; | |
} | |
} | |
Version 2: | |
package com.example.otto.sample; | |
public class SomeKindOfEvent { | |
public final EventData eventData; | |
SomeKindOfEvent(EventData eventData) { | |
this.eventData = eventData; | |
} | |
} | |
public class SomeKindOfFailureEvent { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would say the choice here lies in how and where you are going to interpret these events (which makes it highly subjective for each event) and the type of data. If the same piece of code is going to do very similar things for both the success case and the failure case then I would choose version 1. If two completely separate pieces of code are going to act based on success or failure then I would break them up. It's hard to say that one version is better than the other definitively. I think both have perfectly valid use-cases and you'd just need to make a decision on a case-by-case basis. Plus, since this communication is already decoupled it becomes really easy to switch between the two should your needs or requirements change!