Skip to content

Make objects extendable by using factories instead of constructors #9

@hoemich

Description

@hoemich

To use the library in actual software projects, it would be great to be able to extend the classes, in order to add domain logic to them.

Currently, in the FeatureModelBuilder allows to be initialized with some instance of FeatureModel. This already allows to initialize it with a prototype of an extended FeatureModel inheriting the original implementation.

Yet, the Builder directly calls new Feature to create new Features. This makes it impossible, to extend Features with meaningful domain logic.
For this it would be great, to allow further configuration of the FeatureModelBuilder, by using a factory method instead, that can be injected.

Essentially I propose a field private Function<String, Feature> featureFactory with a default value of Feature::new but the option to replace it with some factory method for a Feature descendent. A dedicated (functional) interface could of course improve readability.

The same principle could be applied to the various constraints.
Of course, it would then be necessary, to put theese configured objects to use. Currently this is difficult, since UVLModelFactory creates its own instance of the UVLListener which creates its own instance of the FeatureModelBuilder, so eventually there would be some general refactoring necessary, to allow dependency injection and configuration over hard-coded object construction.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions