silexphp / Silex

[DEPRECATED -- Use Symfony instead] The PHP micro-framework based on the Symfony Components
https://silex.symfony.com
MIT License
3.58k stars 718 forks source link

Design problem regarding the service provider concept #957

Closed jacklib closed 10 years ago

jacklib commented 10 years ago

Dear all,

In my opinion, the service provider concept in Silex violates some fundamental OOP concepts of good software design such as encapsulation, the open/closed principle or the single responsibility principle.

The application itself is a kind of servicelocator and at the same time, unfortunately, a global storage for all internal service parameters.

All services and their parameters are present unprotected within the app container and can be changed by each component and at any time. Experience shows that sooner or later, this will lead to some problems.

The use of a third-party service provider almost turns into to Russian roulette due to storing the service parameters in the app-container.

Many young programmers use a framework like Silex because they are inexperienced and hope for a well thought-through structure and thus a better architecture for their software due to such a framework.

Instead, the framework boosts an unstable architecture and, in my opinion, can unfortunately warp the programmer into an improper way of working.

It would certainly not be too complex or laborious, to at least store the service parameters directly within the respective service provider.

Why did they opt for this unsafe concept at Silex?

What do you think of the idea of supplementing Silex accordingly in this respect?

Regards Jack

davedevelopment commented 10 years ago

The use of a third-party service provider almost turns into to Russian roulette due to storing the service parameters in the app-container.

Reminded me of this: https://gist.github.com/davedevelopment/4475927

:)

davedevelopment commented 10 years ago

In my opinion, the service provider concept in Silex violates some fundamental OOP concepts of good software design such as encapsulation, the open/closed principle or the single responsibility principle.

I'm happy for the main/bootstrapping part of my application to violate every single OOP principle. I'm pretty happy for most of my use of the framework to violate OOP principles.

Many young programmers use a framework like Silex because they are inexperienced and hope for a well thought-through structure and thus a better architecture for their software due to such a framework.

I think this is the crux of the problem, I don't think Silex is all that suitable for inexperienced developers.

fabpot commented 10 years ago

At some point something needs to bootstrap the core services, that's the goal of the main Application class in Silex. "Fixing" this would mean to create a totally different framework, so closing this issue.