DTO Interfaces naming convention in PHP

It might be that my question would sound a bit stupid but I would like to find the best way for naming my DTO interfaces. In my PHP application I have following DTO types:

  • Simple (which contains a list of properties), for example CredentialsDTO, PhoneDTO, AgreementDTO.
  • Array-like (which contains an array of single-type DTOs, any of these three), for example AgreementsDTO which contain some AgreementDTO.
  • Complex or Nested (which contains a few other DTOs, either simple, array-like or complex/nested), for example AccountDTO (which contains CredentialsDTO, PhoneDTO, AgreementsDTO).

I would like to create an interfaces for these three types but I don’t really know how to name them.

OK, the first one might be just a DTOInterface, for me it sounds clear, array-like is more complicated, ChatGPT offered me DTOCollectionInterface or DTOListInterface but from my perspective collection MUST have data manipulation methods and list… I don’t really understand how them differ from arrays.

Talking about complex/nested, I think anything is fine so I just wanna know which one is standard-to-use.

Thanks in advance!

5

I can’t speak to any PHP specific parts of this question (there may be naming standards I am not aware of).

However typically you would use concrete classes for DTO’s since you are effectively saying this object is a “bag” of properties representing a real world thing. That’s not to say you couldn’t implement an interface on your DTO’s for example IHasIdentity which provides a get_id() method and this might be something you would want all your DTOs to implement.

Going through your examples:

Simple (which contains a list of properties), for example
CredentialsDTO, PhoneDTO, AgreementDTO.

I would typically just name these Credentials, Phone, etc in that I would put them in a package that indicated they were DTOs, but keep the class names clean. However as I noted at the beginning, the PHP community may have strong feelings about pre/postfixing with the words Interface or DTO.

Array-like (which contains an array of single-type DTOs, any of these
three), for example AgreementsDTO which contain some AgreementDTO.

I question the need for these types of object in a DTO context.
The two cases I have typically seen are either:

  • A parent object such as person having a list, map or set of phones.
  • A wrapper used in HTTP responses.

In the first case the name of the DTO would be based on the type of the parent; Person in this case.

In the second case I would either use a generic “pagination” wrapper that provides additional metadata fields such as current page number and total number of pages or if that is not an option in a particular language, I would create multiple classes clearly named as wrappers: AgreementPaginationWrapper or maybe AgreementPageResponse

Complex or Nested (which contains a few other DTOs, either simple,
array-like or complex/nested), for example AccountDTO (which contains
CredentialsDTO, PhoneDTO, AgreementsDTO).

As noted/hinted at above I don’t see this a special case – whether a DTO is a single object or consists of multiple objects in a hierarchy, naming is still based on the function at that level.

However I will call out one special case, which is DTO’s should typically be tied to bounded contexts in that an Order may be tied back to the Person that created it. In this case we are likely changing context, as a result I would only include a reference (ID) to the Person in the Order not the whole DTO.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

DTO Interfaces naming convention in PHP

It might be that my question would sound a bit stupid but I would like to find the best way for naming my DTO interfaces. In my PHP application I have following DTO types:

  • Simple (which contains a list of properties), for example CredentialsDTO, PhoneDTO, AgreementDTO.
  • Array-like (which contains an array of single-type DTOs, any of these three), for example AgreementsDTO which contain some AgreementDTO.
  • Complex or Nested (which contains a few other DTOs, either simple, array-like or complex/nested), for example AccountDTO (which contains CredentialsDTO, PhoneDTO, AgreementsDTO).

I would like to create an interfaces for these three types but I don’t really know how to name them.

OK, the first one might be just a DTOInterface, for me it sounds clear, array-like is more complicated, ChatGPT offered me DTOCollectionInterface or DTOListInterface but from my perspective collection MUST have data manipulation methods and list… I don’t really understand how them differ from arrays.

Talking about complex/nested, I think anything is fine so I just wanna know which one is standard-to-use.

Thanks in advance!

5

I can’t speak to any PHP specific parts of this question (there may be naming standards I am not aware of).

However typically you would use concrete classes for DTO’s since you are effectively saying this object is a “bag” of properties representing a real world thing. That’s not to say you couldn’t implement an interface on your DTO’s for example IHasIdentity which provides a get_id() method and this might be something you would want all your DTOs to implement.

Going through your examples:

Simple (which contains a list of properties), for example
CredentialsDTO, PhoneDTO, AgreementDTO.

I would typically just name these Credentials, Phone, etc in that I would put them in a package that indicated they were DTOs, but keep the class names clean. However as I noted at the beginning, the PHP community may have strong feelings about pre/postfixing with the words Interface or DTO.

Array-like (which contains an array of single-type DTOs, any of these
three), for example AgreementsDTO which contain some AgreementDTO.

I question the need for these types of object in a DTO context.
The two cases I have typically seen are either:

  • A parent object such as person having a list, map or set of phones.
  • A wrapper used in HTTP responses.

In the first case the name of the DTO would be based on the type of the parent; Person in this case.

In the second case I would either use a generic “pagination” wrapper that provides additional metadata fields such as current page number and total number of pages or if that is not an option in a particular language, I would create multiple classes clearly named as wrappers: AgreementPaginationWrapper or maybe AgreementPageResponse

Complex or Nested (which contains a few other DTOs, either simple,
array-like or complex/nested), for example AccountDTO (which contains
CredentialsDTO, PhoneDTO, AgreementsDTO).

As noted/hinted at above I don’t see this a special case – whether a DTO is a single object or consists of multiple objects in a hierarchy, naming is still based on the function at that level.

However I will call out one special case, which is DTO’s should typically be tied to bounded contexts in that an Order may be tied back to the Person that created it. In this case we are likely changing context, as a result I would only include a reference (ID) to the Person in the Order not the whole DTO.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật