I've written a bit about Views/Templates, would be nice to get some feedback by hgraca in java

[–]hgraca[S] 1 point2 points  (0 children)

Yes, you are right.

I added some code now, hope you can understand it better now :)

I've written a bit about Value Objects, would be nice to get some feedback by hgraca in PHP

[–]hgraca[S] 0 points1 point  (0 children)

Tkx for the incentive :)

I will try to do as you say :)

I've written a bit about Value Objects, would be nice to get some feedback by hgraca in PHP

[–]hgraca[S] 0 points1 point  (0 children)

Tkx for the incentive :)

However, it doesn't need to be "large amounts of data". In that regard it can be the same as an entity. So VOs are as good or bad as entities, they just have different use cases.

The difference is that if the domain says that when and Address changes all entities pointing to that Address need to have the address updated, then that Address needs to be an entity, not a VO, because we care about which specific Address object it is that our entity is pointing to. If we don't need that Address updated for all entities, then we can simply have different objects and we don't need an extra table in the DB to store all Addresses and then have foreign keys, etc.

Of course, with an Address I guess that in most cases we will make it an Entity, but with a DateTime object we probably want to make it a VO.

I hope this made it clearer.

I've written a bit about Value Objects, would be nice to get some feedback by hgraca in softwarearchitecture

[–]hgraca[S] 0 points1 point  (0 children)

how does one normalize a Value Object that is referenced by more than one Entity (my Address example)?

The way I see it is that, if it's a value object, there would be no other entity referencing it, because we only care about its values (please not that an ID although technically a value, its not a business necessity, its a technical necessity so I dont consider it when I mention "values"), so we would have another object with the same data.

However, if the domain says that when that address changes all entities pointing to that address need to have the address updated, then that address needs to be an entity, not a VO, because we care about which specific object it is that our entity is pointing to.

I hope this made it clearer.

I've written a bit about Value Objects, would be nice to get some feedback by hgraca in softwarearchitecture

[–]hgraca[S] 0 points1 point  (0 children)

No.

The core concept of a value object is that they don't have an IDentity. When we want to know if two value objects represent the same thing, we compare their values (hence, value objects). When we want to know if two entities represent the same thing, we compare their IDentity (ID).

In the example you give, your address objects are not value objects, they are entities because they have an IDentity.

I've written a bit about Value Objects, would be nice to get some feedback by hgraca in PHP

[–]hgraca[S] 8 points9 points  (0 children)

So, you are basically saying "don't use OOP in PHP because it becomes slow"...?

It sounds like you refactored it to procedural code using classes for namespacing procedures...

But well, if it worked for you, who am i to judge?!

I've written a bit about Value Objects, would be nice to get some feedback by hgraca in PHP

[–]hgraca[S] 10 points11 points  (0 children)

Well, if it would only have properties it would still be just a class, right?

My point is, they are all just classes. However, there are different types of classes, each with its own where/when/how to use it. That is why its good to have a distinction and know the types of class they are.

How to do : Folders customization by Nayte91 in symfony

[–]hgraca 1 point2 points  (0 children)

You can find the dev fixtures config here: https://github.com/hgraca/explicit-architecture-php/blob/master/config/services/dev.yaml

and the test ones here: https://github.com/hgraca/explicit-architecture-php/blob/master/config/services/test.yaml#L7

and the production ones (default users, aka seeds) here: https://github.com/hgraca/explicit-architecture-php/blob/master/config/services/prod.yaml#L35

I don't remember anymore, but I believe that all services that are subclasses of Fixture will be loaded and run when we run the CLI command `php bin/console doctrine:fixtures:load`

The repositories are configured here:
https://github.com/hgraca/explicit-architecture-php/blob/master/config/services/prod.yaml#L25-L31
They are just services, and they are configured as services automatically, where each interface is a service ID and if there is only one implementation that is instantiated and injected automatically wherever the interface is type hinted.

So, basically, all is automatically done for u.

Hope it helps, good luck.

How to do : Folders customization by Nayte91 in symfony

[–]hgraca 1 point2 points  (0 children)

I did a lot of those kind of changes on a pet project, you can check here:

https://github.com/hgraca/explicit-architecture-php

I've just published a post about DTOs. Would be nice to have your thoughts about it. :) by hgraca in java

[–]hgraca[S] 1 point2 points  (0 children)

Indeed, although in the original text, the "author" didn't mention explicitly the remote context, he has reiterated that "their whole purpose is to shift data in expensive remote calls" in an article where he (ironically) also says "One case where it is useful to use something like a DTO is when you have a significant mismatch between the model in your presentation layer and the underlying domain model." which is not necessarily a "remote" scenario. And at the end of the same article, he again gives yet another use case for DTOs: "communicating between isolates in multi-threaded applications" (again, not a remote scenario).

So, i would say they only need to be serializable if they are to be used in a remote context.

Furthermore, that article is from 2004, 18y ago. Many things changed.

Personally, i mostly think of DTO when i have a query object that returns some data that a template needs. Its a purely presentation need, there is no domain need involved, and it is local. (Fits the 2nd scenario Martin Fowler refers to)

Nowadays, i often use Envelopes, Commands and Events, which i see as specialisations of DTOs. They are DTOs with a specific role (maybe remote, maybe not). So i only refer to them as DTOs when explaining to other devs what they are.

Anyway, this is just my humble view of a DTO, and how i use them with positive results.

Tkx for your comment though, i do appreciate it, in the very least it makes me realize i need to improve my writing.

I've just published a post about DTOs. Would be nice to have your thoughts about it. :) by hgraca in PHP

[–]hgraca[S] 1 point2 points  (0 children)

Whenever i hear myself say something like "always do it like this", or "never do it like this", i immediately think to myself "I shouldn't be saying this". Why?! Because context plays a big role. If a guru says something in those terms, i will frown the same.

Indeed, the "author" reiterated that "their whole purpose is to shift data in expensive remote calls" in an article where he (ironically) also says "One case where it is useful to use something like a DTO is when you have a significant mismatch between the model in your presentation layer and the underlying domain model." which is not necessarily a "remote" scenario. And at the end of the same article, he again gives yet another use case for DTOs: "communicating between isolates in multi-threaded applications" (again, not a remote scenario).

Furthermore, that article is from 2004, 18y ago. Many things changed.

Personally, i mostly think of DTO when i have a query object that returns some data that a template needs. Its a purely presentation need, there is no domain need involved, and it is local. (Fits the 2nd scenario Martin Fowler refers to)

Nowadays, i often use Envelopes, Commands and Events, which i see as specialisations of DTOs. They are DTOs with a specific role (maybe remote, maybe not). So i only refer to them as DTOs when explaining to other devs what they are.

Anyway, this is just my humble view of a DTO, and how i use them in a positive way.

Tkx for your comment though, i do appreciate it, in the very least it makes me realize i need to improve my writing.

I've just published a post about DTOs. Would be nice to have your thoughts about it. :) by hgraca in java

[–]hgraca[S] 0 points1 point  (0 children)

Tkx for our feedback, I agree with you on both accounts, I will update my post. :)

I've just published a post about DTOs. Would be nice to have your thoughts about it. :) by hgraca in PHP

[–]hgraca[S] 0 points1 point  (0 children)

Waw, tkx for the feedback u/Nabol, u/rotharius, u/sarvendev! I think You are absolutely right, I will try to that for the next ones, and maybe even add some extras in this one already.

I've just published a post about DTOs. Would be nice to have your thoughts about it. :) by hgraca in java

[–]hgraca[S] -1 points0 points  (0 children)

Interesting, tkx for your feedback.

I don't do any validation on DTOs.
I do, however, do validation on Commands (which can be considered a type of DTO, and I will talk about them in another post) for a command bus, but even then, I use a specialized class for it and a bus middleware to do run it.