Skip to content

Instantly share code, notes, and snippets.

@bjpeterdelacruz
Created February 18, 2014 08:17
Show Gist options
  • Select an option

  • Save bjpeterdelacruz/9066732 to your computer and use it in GitHub Desktop.

Select an option

Save bjpeterdelacruz/9066732 to your computer and use it in GitHub Desktop.
Revised example of a service that hides implementation details by using a private inner class.
public class ExampleClientService {
private final List<ExampleListener> listeners = new ArrayList<ExampleListener>();
private final List<Example> examples = new ArrayList<Example>();
private final ExampleListenerImpl listener = new ExampleListenerImpl();
public ExampleClientService(ExamplesManager examplesManager) {
examplesManager.addExampleListener(this.listener);
}
public void addExampleListener(ExampleListener listener) {
listeners.add(listener);
}
public void removeExampleListener(ExampleListener listener) {
listeners.remove(listener);
}
private void copyExample(Example example) {
// Copy Example into list and then send list to all listeners.
}
private class ExampleListenerImpl implements ExampleListener {
/** {@inheritDoc} */
@Override
public void goodExampleDispatched(Example example) {
copyExample(example);
}
/** {@inheritDoc} */
@Override
public void badExampleDispatched(Example example) {
copyExample(example);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment