What are the Slack Archives?
It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.
Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..
Hey people! I hope you’re doing great 💡 I don’t know if this topic was already raised (I am pr
Hey people! I hope you’re doing great 💡
I don’t know if this topic was already raised (I am pretty sure it was already mention by someone), but I would like to put it on the table. It’s about Value Objects (VO). Let’s consider a real and useful example: The Sku
. Wouldn’t be nice to have an Sku
Value Object which can ensure the consistency of its value at the time when it’s being used or expected?
Currently we are using primitive data (int
, float
, string
), or other Transfer Objects, in all Transfers, but wouldn’t be nice to use VO for some values instead of the raw type? I think the Sku
is a nice example:
final class Sku { private string $sku; public static function fromString(string $sku): self { Assert::notEmpty($sku); // or whatever assertion logic that you want to have return new self($sku); } public function asString(): string { return $this->sku; } }
I was thinking, as something that could be customised by the end client, similar as we can define the Transfers (and generate them out of the box based on some custom xml configuration). Usually a Sku
must be in a certain length and never being empty, so such rules/assertions could be customised 🤔 Of course, this Sku
is just an opportunity example of a simple VO that could be applied to some other (more complex) VOs.
The clear benefits of this proposal/idea is that you can expect certain types in your functions that depend on specific VO and not simply raw types. I think this would be an awesome step to improve the user experience with Transfers Objects. What do you think?
Comments
-
I think it’s a great idea, although I am not sure about the immutability aspect of it while working on Spryker projects. Part of the coolness (and headache) of transfer objects is that they are actually mutable and allow side effects even (nightmare or feature?). It allows for a lot of flexibility especially when developing a lot of things in core. Now should we have VOs allowed in Transfer object definition and let projects run away with it? Absolutely! It might be a great way to ensure some sort of sanity on project level. But those VOs will probably not appear on core level. Just FYI, we currently have such support for VOs of Spryker’s internal implementation of https://github.com/spryker/decimal-object. I am not sure how extendible it is to enable other kinds of VOs though
0 -
Also as transfer objects are serialized from/to JSON when we can ZED from client we need to make sure that we do not break this.
0 -
You can also make your own transfer objects by extending AbstractTransfer or existing transfer.
0 -
If you’d like to introduce such things in your project, maybe take a look at
\Spryker\Zed\Transfer\Business\Model\Generator\ClassDefinition::SUPPORTED_VALUE_OBJECTS
. Just keep in mind that overwriting Transfer module on project level just for this particular feature might stop you from gaining access to future Spryker bugfixes/features in the Transfer module!0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 76 Spryker News
- 929 Developer Corner
- 787 Spryker Development
- 89 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 26 Job Opportunities
- 3.2K 📜 Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 70 Spryker Safari Questions
- 50 Random