Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

New observer implementation #54

wants to merge 2 commits into from

Conversation

frnlpz
Copy link
Member

@frnlpz frnlpz commented May 7, 2017

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.


class Roulette{

var observer: CategoryObserver? = null
Copy link
Member

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,
Copy link
Member

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>
Copy link
Member

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 😅

Copy link
Member

@Cotel Cotel left a 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 🙏

@frnlpz
Copy link
Member Author

frnlpz commented May 7, 2017

Now it's much clearer! Thx @Cotel

I'm writing some tests between this evening and tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants