Write a comment
Writing comments is only allowed to registered users, registration is free and does not require an email address and can be done quickly here.
Writing comments is only allowed to registered users, registration is free and does not require an email address and can be done quickly here.
Great blog post, as usual. I really liked the visual "map" that you followed from LTR while reading throughout this. =)
I think you may add an explanation or 1-2 sentences, when going from factory method to factory class, as to "why" the actual implementation class remains "create private" and that this is the key reason behind the required friendship? The thought or rather design aspect behind it might be useful for others. But you may also say that it goes too deep into basics, which I also understand. :)
Based on the content may we expect a smaller, additional, post about the mentioned injector? I think it would be a great addition and fits neatly with your IDE actions and this post!
Thanks for the feedback, have added one sentence for this. The topic with the incjector I have to check, because there will be an update for MIA with some adjustments and an explenation, what is generated in the system.
Question on testable
Hi, great article! As mentioned I also like the evolutional approach of the example.
What did not understand was during the explanation of the static factory.
" If the factory provides us with a test implementation in the unit test, for example, via an injector into the factory, then we have created a testable environment."
Using such a static factory I hard,y see any option using an Injector or any other option to injects a factory that provides mock / stub objects.
My thought was ... "Ah he'll explain singleton first, than make the factory a singleton" as "final solution".
All tose implementations I do not see any nice option for a dependency injection etc ... What Do I miss?
Hi Timo,
after you build the injector, set it as global friend in the factory. Set a static attribute as instance you want to inject and enhance the create method. If the attribute is set, return it, if not, create a new instance. The injector is set to FOR TESTING, so no one can use it outside ABAP Unit Tests.
Benefit You do not have to change the current implementations, if you decide to develop the injector and build it testable.
Greetings Björn