-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
Is your feature request related to a problem? Please describe.
There is a common pattern of instatiating domain objects from infrastructure, for example Entity could be instantiated from its database representation or event. Currently we have to extract props from those and use .create()
or build additional factory methods.
Both approaches can lead to code duplications and spreading the same logic over the codebase.
Describe the solution you'd like
Entity
has .toObject<this, T>(adapter: Adapter<this, T>) => T
method.
My proposal is to add .fromObject<this, T>(adapter: Adapter<this, T>) => this
.
Describe alternatives you've considered
- extract props from those and use
.create()
- implement additional factory methods inside of the entity or wherever in the code base.
- implement
Adapter
interface(right one imo) and manually use its method.adaptOne
Why bad?
- Extracting props leads to code duplication, as sometimes props will be extracted from the same type of object, but in different places of code, leading to duplication. This could be solved by creating a method, which will be handling this, what brings us to 2nd alternative.
- This method could bring us to chaotic spreading of such adapter methods. As there is no clear defenition of where should be such functions extracted and how would they look.
- Is good, but in my opinion code style would be more consistent if we had
.toObject
and.fromObject
.
Metadata
Metadata
Assignees
Labels
No labels