guigarage / ObserverPattern

Basic Java observer API
Apache License 2.0
7 stars 7 forks source link

"Writable" similar to "Observable" instead of just "Property" #12

Open manuel-mauky opened 7 years ago

manuel-mauky commented 7 years ago

At the moment you have a Observable interface which defines methods for "read-only" access and the Property interface which extends Observable and adds the possibility to change the value. However, this means that if you have an instance of Property you can allways "read" the current value.

I suggest to add an interface Writable (or find a better name) that defines "write-only" methods. Then Property should extends both Observable and Writable. This way you can have an instance of Writable that the developer can only use to change the value but not to read the value.

This way you could be more specific and expressive when designing the API of your component. If your Component only provides an Observable to the outside world it's clear that this is only intended to get values from the Component. If you provide only an Writable it's clear that this is only intended to set values into the Component. If you provide a Property it's clear that both is intended.

This should also be considered when designing binding support. There should be something like a unidirectional binding but with inversed data flow. If you have an instance of an Observable you could bind this to a Writable so that when the value of the Observable changes it's pushed to the Writable.

The idea behind this comes from my JavaFX projects where I had situations where I wished for something like a WriteOnlyProperty instead of only Property and ReadOnlyProperty.

hendrikebbers commented 7 years ago

Sounds good. I will try to refactor this.