Created
February 18, 2014 08:17
-
-
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.
This file contains hidden or 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
| 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