[Opinion] Using DTOs as part of abstraction layer #125
CristianHG2
started this conversation in
General
Replies: 1 comment
-
I would certainly use data objects as a typehint! I think they are perfect to encapsulate a certain structure which is the same across your code. That being said, I wouldn't do it for methods with only 5 parameters because you need to name these data objects since you all need to name hem which is most of the time the hardest part 😄 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
One of the big benefits of TypeScript is being able to provide struct-like types for objects, the same goes for this package. TypeScript however also provides the option to implement interfaces on functions, and have members of those interfaces also be other interfaces or standard object types.
PHP interfaces currently don't support property declarations, which makes writing abstractions that might be expected to have certain properties present. Naturally, you might consider just passing that information over a method call, but when working with objects that might have 10+ properties, it doesn't scale very well and you're left with a bunch of useless boilerplate.
Data Objects are relatively agnostic to their context since all the raw data is self-contained in its own instance, would you consider DTOs to be usable as a type-hint used in the abstraction layer? Let's say for type-hinting a return type? Or would you classify this use case as more of an anti-pattern?
Beta Was this translation helpful? Give feedback.
All reactions