-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Hi,
I've been facing some issues wrt artefacts creation and visibility modifiers. Currently, this is what's being done:
- Artefacts can be created without taking their #init's modifier into account
- If the default constructor of a class that extends Artefact is anything but public, it can't be created as an artefact (ie, by means of
makeArtifact(...))
I find this quite confusing. I believe that, when creating artefacts, the init method's modifier should be considered, and its modifier only, not the default constructor's. This way I can create ordinary and artefact instances out of the same class, the former by using new and the latter by using makeArtifact, while still keeping the visibility modifiers' semantics.
This is a real problem when tying to implement some design patterns. For example, I tried to implement an adapted version of Joshua Bloch's Builder design pattern to work with artefacts but I can't have it properly done as I can't have private constructors. Here's how I tried to implement it:
- SimpleClass extends Artifact, has a private constructor with SimpleClassBuilder as parameter, and a public init method that has SimpleClass as parameter (this would be something like an "object-artefact copy constructor");
- SimpleClassBuilder is a SimpleClass' static inner class whose build method returns a SimpleClass ordinary instance
Note that a SimpleClass artefact can only be created if we have an ordinary instance of it, which can only be obtained by using SimpleClassBuilder. I could have made SimpleClassBuilder an artefact whose build method creates a SimpleClass artefact and returns its ArtefactId. However, this would incur unnecessary computational costs (due to the use of reflect for everything including setters in the builder) and if I had a parser class (which is also my case), for example, that uses the builder, this would have to be an artefact as well. After the parsing and building, I'd also need to dispose the builder and parser artefacts.
Could you please give your thoughts on this, @jomifred @aricci303 ?
Cheers.