Skip to content

Start refactoring of ObjectFactory#6162

Draft
alxbilger wants to merge 1 commit into
sofa-framework:masterfrom
alxbilger:refactorobjectfactory
Draft

Start refactoring of ObjectFactory#6162
alxbilger wants to merge 1 commit into
sofa-framework:masterfrom
alxbilger:refactorobjectfactory

Conversation

@alxbilger

Copy link
Copy Markdown
Contributor

Early stage of a simplification of the object factory (now ComponentFactory).

Two unanswered questions:

  1. How to treat the template? (related to [Core] Improve UX when defining template of a Component #6161
  2. How to select the template (canCreate)? And how to get rid of create?

runSofa compiles, but no guarantee for others.

Current changes allow:

<Node name="root">
    <RequiredPlugin pluginName="Sofa.Component.StateContainer"/>
    <MechanicalObject/>
</Node>
<Node name="root">
    <Sofa.Component.StateContainer.MechanicalObject/>
</Node>

By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@alxbilger alxbilger added the pr: status to review To notify reviewers to review this pull-request label Jun 22, 2026
@damienmarchal

damienmarchal commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

I would be happy to discuss this point and it is worth having a look there as there was lengthy discussion on the topic in the past.

If I remember correctly, the general idea was that both canCreate and create should be removed.
The observation was to canCreate/create was mostly used to implement two different things:

  • template deduction/inference
  • component checking or initialization (regarding input/output correctness checking)

To move forward the idea was thus to:

If there is a deep refactoring of ObjectFactory, I would also recommand adding the namespace features and user define aliases suggested in:
#2512 and

And also to remove the use of GetClass which cause a code bloat.


const objectmodel::BaseClass* getClass() override
{
return RealComponent::GetClass();

@damienmarchal damienmarchal Jun 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are refactoring component factory could we drop this please.

If I remenber correctly this single line is causing a compilation code bloat (just to provide the class name). When we are registering a component into the factory the class name could be passed with a std::string instead of relying a complex custom "reflection" system.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, the only reason I had to keep this function was to list components deriving from another, using the method hasParent in BaseClass. If we find another mechanism for that (or if we remove this feature), we can remove this usage in the factory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: status to review To notify reviewers to review this pull-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants