As a developer I would like to flag certain entities that should not be instantiated manually so that I can control when and how they are created - Mendix Forum

As a developer I would like to flag certain entities that should not be instantiated manually so that I can control when and how they are created

3

The simplest use case for this would be to support the singleton pattern, where only one object should be created of a specific entity.

But it could prove useful also for other use cases for example by preventing developers from creating sessions or other system objects in a microflow.

asked
4 answers

@Jord and only before-commit is not failsafe. You need to do more. I created a pattern for it a while ago, but that is far too many clicks-and-drags when you create it. Would love to see Andrej’s idea implemented.

Created

@Jord yes that is possible but a before create event handler would only offer run-time protections while the feature that I am suggesting would prevent such error at design time.

Created

Though i haven’t used it so far, the singleton pattern could be easily guarded by an before-create event handler, right? Just check if there is already an object in the database and if so, throw an error.

Created

Singleton pattern is one of the things, which I use almost in every project (eg. for something like an app configuration or App status) and usually realized via DS-Microflow. But this is not failsafe. 

In Java you can set the constructor_ of a class to private, to prevent creation from outside of the class. Would be nice to have a similar solution in mendix.       

Created