2
I built two packages in PHP, each of these perform very different functions, however, both implement practically the same interfaces and abstract classes.
Because of this I created a third package containing only the interfaces and abstract classes used, that is, this package contains the basic skeleton shared by the other two libraries. The interfaces are below the Contracts directory, while the Auxiliary and Connector directories have abstract classes:
Already one of the packages has the structure:
However, I think this organization does not seem very satisfactory. Any idea how to improve this, or even organization suggestions?
Note: Loading via autoload is being done by Composer
The idea is to separate in a package the abstract classes, interfaces and traits standards for 2 packages or more...
I think it can be useful, yes, but it will be reused in more than one project. I did it myself with a project I had, because if I have to update it doesn’t affect the rest of the project.
– Guilherme Nascimento
I get it. So everything indicates to be a good strategy. And in your opinion, could this file structure be different? Something about it bothers me.
– Fábio Jânio
Yes, but I didn’t identify anything suggesting place and name of abstract classes, interfaces etc
– Fábio Jânio
I understood. Well, my question was, in the generic package I have the interfaces and abstract classes. In the main packages, which implement these interfaces and abstract classes, I have specialized classes, but with the same name. For example: Pacotegenerico Cpu Libraries and the main package Pacoteprincipal Cpu Libraries. The difference is that the main packages are specialized classes. It is considered inappropriate to have the same interface name for the class?
– Fábio Jânio
I personally would never divide by folders pacoteprincipal Cpu libraries, always do
Vendor\Categoria\Cpu
, and everything goes inside the vendor folder controlled by Composer (it would be nice to study it first) and if a class repeats the name and still uses the same namespace it is already wrong. It’s not wrong if the namespace is different.– Guilherme Nascimento
Thank you Guilherme, I posted on github https://github.com/crphp/wmi. which makes use of another https://github.com/crphp/core. Obviously I will have to improve a lot, but at least it is an initial step.
– Fábio Jânio
I wouldn’t have split into two repositories, just create a folder called
./src/Core/
and another./src/Wmi/
– Guilherme Nascimento
It is that you will have two other distinct packages that will use core. And they don’t depend on Wmi, so I didn’t want to force the user to install Wmi if for example he only wants Ssh
– Fábio Jânio
In this case it makes sense, it did very well. just a detail, I noticed that Wmi depends on Core and already this in Composer.json, it was great so.
– Guilherme Nascimento
I’m even writing an SSH library that uses the abstract Connector class and all other interfaces. In the coming days I should already be publishing, this approach is saving me enough development time
– Fábio Jânio