I didn't meant to imply that you should remove the factory capability. For example this is supported by the Symfony 2 DIC. So there would be no new object created upon a request but the already instantiated object used.
Look at this example:
public function __construct(Db $db, Util $util)
$this->db = $db;
$this->util = $util;
public function __construct(Db $db, SomethingElse $somethingElse)
$this->db = $db;
$this->somethingElse = $somethingElse;
Assuming both test classes are registered in the DIC when we get both from the container, the instance of $db will be the same. No new object is created as the DB is created using a factory method (see http://symfony.com/doc/current/components/dependency_injection/factories.html ).
And it is also good design to explicitly specify your dependencies.
Here are a couple of articles dealing with the pros and cons of DICs:
Speaking of my own observation of this I'm using DICs in PHP for about 4 years now. At the beginning I was very sceptical about the whole concept but after working for so long with them I really see the benefits and advantages it brings.
You design your classes in a more structured, clean, and useful way. :smile:
What I want to propose good code quality.
Btw., Mark, I really enjoy this conversation. It gives me a good feeling the developers are open for discussion even if it turns out that the suggestion won't be implemented (which I don't hope for this ;)).
Why would the database class be different than any other class? What if I want to test my code which depends on the database and I have no way of mocking it to have testing in isolation? Having it as a injectable dependency makes mocking it in tests easy. I just want to state that this major version bump is the best opportunity to establish well tested and proven design principles which lead to better and testable code.
Great to get some insights about the new structure. But instead of introducing multitons wouldn't it be more logical to use a dependency injection container and make it available anywhere? It would enhance testability of the code and use cases like this are also well supported. App developers would also benefit from a DIC as they could easily specify which services they need and get a perfectly configured instance from the container instead of wiring all the needed dependencies themselves.
There are various lookup ways possible so it depends on the concrete implementation. You can also have a static class map with classes anywhere which could be then registered with the autoloader. Here is an example for PSR-0 compliance: https://github.com/composer/composer/blob/master/src/Composer/Autoload/ClassLoader.php - there are also implementations for class maps and even an generator for autoloading.
Thanks for the answers, Mark. Even if you don't follow PSR-0 completely, having an autoloader is great and useful. I just want to make sure it will be possible for nearly any custom application to register themselves at the autoloader and be available anywhere.
Looking forward to more info about the new suite. :)
This sounds quite awesome. But I have some questions you might be able to answer already:
Will you make use of third party components for certain parts of the application like Symfony components?
Will you follow the PSR-0 standard for autoloading?
Will the application be real UTF-8?
Will the already available XML-RPC API have more options or changed against another implementation?
Thanks for your extensive answer, Brandon. Even if IPS doesn't consider adding ES in the near time, can I assume that the current product would allow me to develop an addon who would offer ES integration?
Both of you are free to chose not to use it if it would be an AddOn.
Elasticsearch would provide nice features like facetted search (like Amazon where you can filter through the set of results), schema less documents, JSON-REST-API, suggest search and so on.
And the fact XenForo is offering such an solution shouldn't mean IPS should not.
The search is one of the most delicate parts of the forums and having members and guests finding valuable information it is necessary to have a good search. While database search is good for small communities, it is soon outgrown when the community evolves or the fulltext search isn't simply working the way it should.
Dealing with Elasticsearch myself for an project, it would be great if IPS could provide a addon or built-in support for it. As per announcement , Xenforo is going to provide an addon which will provide Elasticsearch.