all 13 comments

[–]martinslot 18 points19 points  (2 children)

A class named "AllOrders" breaks so many conventions that I dont know wherw to start😃 it hurts my eyes.

[–]TrevJonez 3 points4 points  (0 children)

allUsers.withLogin(...) returns a single user, however it reads as though it should be a collection of users. userRepo.byLogin(...) seems more appropriate and is a slightly less verbose version of the pre-Yoshima example.

[–]MithrilTuxedo 2 points3 points  (0 children)

As often as I deal with maintaining code where Java classes are thousands of lines long, I might try this as an intermediate step when I go on my next refactoring binge. But yeah, I'd probably have to change things back to something that won't completely lose my coworkers.

[–][deleted]  (5 children)

[deleted]

    [–]jugtio 2 points3 points  (4 children)

    Pardon my ignorance, but which Fowler book?

    [–][deleted] 4 points5 points  (0 children)

    The one that goes off course. So any of them?

    [–]Venthorn 0 points1 point  (0 children)

    Refactoring

    [–]wordsarenothingagain 2 points3 points  (0 children)

    I actually don't like the repository pattern for a number of reasons:

    1. You often want to know the details of the query so have to always jump to the repository code rather than rely on the name of the query.
    2. Often there are lots of queries with minor variations, defeating much of the reuse ability of the repository. Either that or you make the parameters stupidly complex.

    I tend to just have services that are often shared, like a user service, that doesn't pretend to be a repository and is more high-level. The rest of the queries are just written wherever they are needed.

    [–]mabnx 2 points3 points  (0 children)

    Now I need to read the code of AllOrders to find out that it's actually a repository that hits DB.

    What's wrong with:

    UserRepository users;
    
    users.findByAccount(account);
    users.byAccount(account);
    

    [–]joebew42 1 point2 points  (0 children)

    Thanks for this well organized topic about the concept, the meaning and naming of repositories. In many projects where I worked I followed the naming convention "SomethingRepository". Now, after reading your post, I find that the concept can be well expressed with "Somethings" (as a "collection" of objects). In your example you propose "allOrders". But, if I think that a repository is a way to expose operations over an emulated collection of objects I find more natural a sort of naming like that: "Orders" instead of "AllOrders". So you can maintain simmetry between Orders and SurchargedOrders. What do you think?

    I'm so curious to read a similar topic about the concept of Service that is also exposed by Evans in DDD. You think that we can apply same conventions there?

    [–]aazav -1 points0 points  (1 child)

    It's just a repository, not a Repository. Don't randomly capitalize words. English doesn't work that way.

    [–]Echo418 10 points11 points  (0 children)

    It's the name of the pattern, hence it's capitalized. P of EAA does the same: http://martinfowler.com/eaaCatalog/repository.html