dddshelf / ddd-in-php-book-issues

Leave your comments, improvements or book mistakes as an issue! Thanks ❤️
https://leanpub.com/ddd-in-php
28 stars 2 forks source link

Naming Conventions Repositories #51

Closed webdevilopers closed 8 years ago

webdevilopers commented 8 years ago

Some examples show InMemory (Redis) and Doctrine (ORM) Repositories. Looking at some Java examples of the red book there are NoSQL examples and they are named after the "DB" e.g. "MongoFooRepository".

Since Doctrine is just the "Mapper" I think repositories should be named similar to the red book examples. Naming them ORM and ODM Mapper could be a possible solution but regarding MongoDB and CouchDN, SQL and MySQL etc. I think it would be better to name them as follows:

I'm currently working and projects blending ORM and ODM via Doctrine and sometimes I have Foo Repository for Mysql AND Mongo. So I had to rename them.

But I guess this is not relevant enough to change half of the book. :) Still would like to hear your thoughts!

MacDada commented 8 years ago

One thing is sure for me: interface FooRepository.


As for the implementations, it doesn't matter that much, as long it's obvious what it represents.

In most cases I have ArrayFooRepository or InMemoryFooRepository. Or I don't, and use mocks in tests.

For production use, I create DoctrineFooRepository.

In a legacy project I also have MysqliFooRepository.


As for ORMFooRepository – there are many ORMs – the name would not tell me much about implementation, so I would avoid it.


As for DoctrineOrmFooRepository and DoctrineOdmFooRepository – if I had both, I would name them like that. But I usually have one, so I just do DoctrineFooRepository. And it's ORM. I never had to rename it, as I never migrated from Orm to Odm. If I did, I'd just rename stuff – should be easy in this case.

But, if I did a library (not a full app), there would be a bigger chance of multiple implementations for the start or in the future – so I might differentiate them from the beginning.

theUniC commented 8 years ago

I think that naming them DoctrineORMFooRepository or DoctrineODMBarRepository it's a pretty simple and good solution. I like to tend to naming them according the technology they use.

webdevilopers commented 8 years ago

Good compromise! Though Doctrine is the ORM and Mysql or Mongo feels more like a "technology". ;)

theUniC commented 8 years ago

That's a way to see it. Doctrine can be treated as another technology as well. :)

yvoyer commented 7 years ago

Using a folder for Namespacing could be a good compromise.

Platform\Orm\Doctrine\FooRepository Platform\Odm\MongoDb\FooRepository

webdevilopers commented 7 years ago

I like the idea by @yvoyer of using platforms. Reminds me of the @beberlei Doctrine Extensions structure: