async-interop / event-loop

An event loop interface for interoperability in PHP.
MIT License
170 stars 9 forks source link

Merge Registry into Driver? #85

Closed kelunik closed 8 years ago

kelunik commented 8 years ago

I think it would be better to merge Registry into Driver and make Driver an abstract class and those two methods final.

sagebind commented 8 years ago

I don't know how many positives or negatives would be in this approach, but it would no longer be possible to write a driver that extends a different, non-driver class.

sagebind commented 8 years ago

If the goal is to get rid of the trait, another idea would be to implement the registry as a separate binding service:

class Registry
{
    public static function fetchState(Driver $forDriver, $key) { /* ... */ }
    public static function storeState(Driver $forDriver, $key, $value) { /* ... */ }
}

I think the existing trait approach makes sense though and is the situation traits were meant for.

bwoebi commented 8 years ago

@coderstephen That, IMO, is the absolute worst solution (a class Registry).

Also, I don't think we should have an abstract class as base. It's not our task to define the implementation. We can recommend implementations and that's all. That's why we have the trait. Users shall be able to easily override it (e.g. put a var_dump() in their driver implementation to debug and call the trait method then).

kelunik commented 8 years ago

@bwoebi If possible, we would have implemented it in the Loop class like we did initially. This is something that really shouldn't change between drivers. It should always be the same. You can still edit Driver.php to add that var_dump temporarily.

I don't know how many positives or negatives would be in this approach, but it would no longer be possible to write a driver that extends a different, non-driver class.

If you follow the single responsibility principle, which you should, your driver shouldn't ever extend another class that's not a driver itself.

Any driver implementation really is a driver, not only behaves like one.

bwoebi commented 8 years ago

Perhaps you're right. The only thing I really disagree with is making the methods final.

kelunik commented 8 years ago

Not sure whether they should be final. But I think it makes sense, because it's nothing a loop should change. It's code belonging to the accessor really, we just can't put it there without memory leaks if we want to support reusing loops with the same state again.

kelunik commented 8 years ago

@assertchris @AndrewCarterUK @WyriHaximus @trowski What do you think?

WyriHaximus commented 8 years ago

Not sure yet, learning torwards implementing this in the Loop as we initially did.

kelunik commented 8 years ago

@WyriHaximus That doesn't work with reusing loops and having the exact same state then again.

kelunik commented 8 years ago

PR is now available: #87

WyriHaximus commented 8 years ago

@kelunik looking at #87 that makes sense :+1:

assertchris commented 8 years ago

Yeah, on reflection, I think this is neater.

kelunik commented 8 years ago

Can we go ahead and merge the PR?

kelunik commented 8 years ago

Merged.