podam icon indicating copy to clipboard operation
podam copied to clipboard

private and protected fields

Open lowcasz opened this issue 3 years ago • 3 comments

I think a lot of fields should be visible by its child class. For example: We have AbstractRandomDataProviderStrategy with private field typeManufacturers I would like to add new typeManufacturer depends on field name. When field name match i want use my custom manufacturer, but if not use the default. In this situation I have not possibility to get typeManufacturers in implementation which extends this abstract class.

lowcasz avatar Jan 25 '23 13:01 lowcasz

Hi,

This is breaking the data encapsulation. To achieve what you want you should inherit from the default type manufacturer

    @Override
    public String getType(DataProviderStrategy strategy,
            AttributeMetadata attributeMetadata,
            ManufacturingContext manufacturingCtx) {

        if ("myAttr".equals(attributeMetadata.getAttributeName())) {
            String retValue;
            /* Customization here */
            ...
            return retValue;
        } else {
            return super.getType(strategy, attributeMetadata, manufacturingCtx);
        }
    }

and then just replace default manufacturer with custom one

   dataProviderStrategy.addOrReplaceTypeManufacturer(String.class, customManufacturer);

Thanks, Daniil

daivanov avatar Jan 28 '23 11:01 daivanov

Let me know, if there is a need for clarification.

Thanks, Daniil

daivanov avatar Feb 04 '23 12:02 daivanov

Yes of course. But for me this encapsulation is too strictly. It is abstract class only. I wanted do this, because of standard implementation is generally ok as concept, but attribute strategies are not working there.

lowcasz avatar Feb 06 '23 15:02 lowcasz