Conversation
| } | ||
|
|
||
|
|
||
| class Subscription<A> internal constructor(internal val update: (A) -> Unit, |
There was a problem hiding this comment.
Internal constructor??? what is that? 😲
There was a problem hiding this comment.
internal is like in java a class without public, is a visibility package only.
There was a problem hiding this comment.
There was a problem hiding this comment.
So this is for testing purpose I suppose?
|
|
||
| open class Observer<A>(private val value: A) { | ||
|
|
||
| private var subscription: Subscription<A>? = null |
There was a problem hiding this comment.
Why do you need a Subscription class? 🤔
There was a problem hiding this comment.
to subscribe and unsuscribe
There was a problem hiding this comment.
But the register method is in the publisher, you only need to add another method to remove subscriber
|
|
||
| } | ||
|
|
||
| open class Observer<A>(private val value: A) { |
There was a problem hiding this comment.
Why open class? You could have made it abstract or even an interface with implementation (I think Kotlin let to do that...)
There was a problem hiding this comment.
Yes, should exist a Observer interface, but for this example is more clear without a one component more.
| @@ -1,13 +1,77 @@ | |||
| package oop.Proxy | |||
|
|
|||
| interface Car { | |||
There was a problem hiding this comment.
Is this a missed commit or it is included too?
There was a problem hiding this comment.
This is a gost commit lol hahaha
| fun main(args: Array<String>) { | ||
|
|
||
|
|
||
| var carVirtualProxy = CarVirtualProxy({ RealCar("tonilopezmr", 5) }) |
There was a problem hiding this comment.
Why do you wrap that constructor parameter in a lambda?
There was a problem hiding this comment.
To be lazy, do you remember?
Because you don't want to do a new inside https://github.com/CloudCoders/Design-Patterns/pull/55/files/ad103bb6a835ebef42ee91260faf98a8889db69e#diff-50695285805be0311b4d9813df63d03dR22
There was a problem hiding this comment.
Oh, I confused it with CarProtectionProxy which has not function as a constructor parameter. My bad 😝
There was a problem hiding this comment.
Because Virtual is lazy
| val observers = mutableListOf<Observer<String>>() | ||
| val subject: PublishSubject<String> = PublishSubject(observers) | ||
|
|
||
| "register a observer" { |
There was a problem hiding this comment.
Wow nice and klean 😏 I like it 👍 🔝
There was a problem hiding this comment.
Yes I was starting with a JUnit test, but how I have created a one file for 3 classes, I prefer use this kind of test to separate differents things, like Subject and Observer 👍
You can notify for all observers but some observers can subscribed and unsuscribed in any moment, this is very common in Android because Screens are subscribed and unsuscribed every time.
Example output:
Coverage: