New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Agree on naming for data access objects Dao Vs Models in core platform and plugins #7540
Comments
Examples:
|
👍 for
|
Yeah we could, the idea is that |
To me |
I agree with @diosmosis that Model in many PHP frameworks is correlated with DTO. Regarding to communication with data storage (database, cache, files etc.), I don't care if it will be a DAO or Repository (IMO definition of both is similar). More curious to me is how you want to handle such things:
The problem is simple if we are limited to SQL databases, but if we would like to extend our technology stack with e.g. nosql, graph dbs etc, then it's much tricky to create a good architecture. |
Let's have Model\Something and Service\SomethingService then. A repository is different from a DAO as it represents a collection of objects (model objects). In Piwik I have yet to see objects being used (or at least used for real). For example there are no objects to represent users, array of values are used instead: https://github.com/piwik/piwik/blob/master/plugins/UsersManager/Model.php#L43-58 If some plugins indeed introduce the concept of repositories and associated model objects we could use the repository naming for this specific case, but currently (at least in Piwik's codebase) what we have are DAOs. See also this question that sums up the difference pretty well.
I don't expect any refactoring in the codebase to happen now. The goal of this issue is mainly to define the naming to use for new classes and existing classes that will be refactored. But this is just a renaming, it doesn't imply introducing ORM (data mapper), changing the way the database is handled or how queries are created. Those are separated topics.
Different topic (but I agree it's an important one). Naming our classes DAO doesn't affect the locking to MySQL. |
👍 to use we started using it quite a bit already as there are 15+ |
Regarding |
Nope those classes should be renamed (not necessarily now) Queries go in DAO, those classes are meant to handle persistence. Model classes are objects that represent an instance of something (e.g. a user, a request to track, an alert, a report, an email, a date…). Model classes can contain domain logic related to themselves (e.g. a date can modify itself, etc.). Those are the classes that contain state. Piwik currently uses a lot PHP arrays instead of model classes. Services are singletons (through the container, not actual singleton To sum up:
|
Ok, so next steps would be:
|
For being able to use alternative storages, I think there are 2 options:
|
Has anyone thought about the placement of services? Ie, should they only be defined by plugins or can they exist in core? If they can exist in core, how would they be organized? Since all the important Piwik logic should ideally exist in services, I think it makes sense to organize Piwik around these services (which may not actually exist yet). If we can put services in core, I think it would be good if the second level namespace in Piwik\ was for core services, eg, Or we could put these services only in plugins. Eg, the ArchiveInvalidator service and possible future services like an ArchiveAccess service (what I imagine the future of the Archive.php class would be) could be put in a plugin dealing w/ report caching (ie, the archive tables). |
Created follow up issue #7571 refactor most of SQL currently spread in codebase to be all within Dao classes |
Regarding discussion about Services I created separate issue here: Discuss how we define, name, and namespace Services objects #7572 - feel free to comment there with your thoughts! |
@piwik/core-team it seems we all agreed to use |
The goal of this issue is to discuss within the Product team a common naming for DAO. By not having a common design here we are mixing several notations and it is causing confusion. To create the best open analytics platform, we need to get these things right :-)
These classes contain SQL queries and little/minimal logic around SQL queries.
So... shall we name them
Dao
, eg. https://github.com/piwik/piwik/blob/master/core/DataAccess/RawLogDao.php or shall we name themModel
or some other name?Once agreed we can change all current code to use the decided name. (this can be followed up in other issue or here)
The text was updated successfully, but these errors were encountered: