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..

Is there a best-practice on where to put cross-module constants in the Spryker architecture? I am ha

U010DNAA3QW
U010DNAA3QW Posts: 55 🧑🏻‍🚀 - Cadet
edited July 2020 in Help

Is there a best-practice on where to put cross-module constants in the Spryker architecture? I am having a case in a project now where I need to use one constant value in several (by itself independent) modules - any suggestions?

Comments

  • U010DNAA3QW
    U010DNAA3QW Posts: 55 🧑🏻‍🚀 - Cadet

    I am currently thinking about two options:
    1. Create a FeatureAbcConstants class in one of those modules, leading to e.g. using the constants as Pyz\Zed\ProductLabel\FeatureAbcConstants::MY_NICE_CONSTANT . This is a contradiction to "don't create direct dependencies between modules".
    2. Create a new namespace MyCompany and drop the constant in a class there, so e.g. MyCompany\Constants\FeatureAbsConstant::MY_NICE_CONSTANT and reference this from the Spryker modules... this seems like the "cleaner" solution, although it feels a bit dirty to create a completely new top-level namespace.. the advantage here is that those "project-level" constants would be outside of the normal module-layer of Spryker

  • The third one:
    You can create a constant in both modules. In main module you create just a constant, in others add @uses tag in dockblock with reference to main module

  • U010DNAA3QW
    U010DNAA3QW Posts: 55 🧑🏻‍🚀 - Cadet

    @UR1QYK8MC thanks for the answer, but this creates duplicate code, and my experience is that then someone just changes it at one place, and forgets the other one? 😄

  • Unknown
    edited July 2020

    that’s why you need @uses. But I agree with you. I personally think that on project level you can simple live with dependencies between modules and use constant from another module

  • Andriy Netseplyayev
    Andriy Netseplyayev Sprykee Posts: 519 🧑🏻‍🚀 - Cadet

    Agree 100% here:

    on project level you can simple live with dependencies between modules

    don’t over-complicate your code with de-coupling things too much. In Spryker de-coupling is important, since there many projects out there with different modules combination.

    Project - is a concrete implementation, where simplicity and readability of the code - is the most important thing.

    SOLID - is a very important principle, but don’t go to it’s extreme, find a “golden middle”