-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New observer implementation #54
base: master
Are you sure you want to change the base?
Conversation
|
||
class Roulette{ | ||
|
||
var observer: CategoryObserver? = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to create a separated object in this case. I think it is more natural if Players are observing the Roulette directly 👍
package oop.Observer2 | ||
|
||
|
||
data class Player (val name: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Player is the observer. The Roulette is observable.
package oop.Observer2 | ||
|
||
interface Observer<T>{ | ||
val list: MutableList<Player> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why must an Observer have a list of Players? This is an unnecessary coupling 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach is really illustrative. Even more than my previous example I think. Maybe we should change it in the README 🤔
Write some tests before merging please 🙏
Now it's much clearer! Thx @Cotel I'm writing some tests between this evening and tomorrow. |
Here's another example of observer pattern. In this case, the goal is to notify players in a game of roulette of changes in the category picked after the wheel has spinned.