-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Do not write components outside the POM !
Instead, in Spec any presenter should be part of a “POM” (Presenter Object Model) with its origin in the application you are using it. For example, all tools in Pharo are part of a single application called StPharoApplication.
This does not means you need to use this application !
StPharoApplication is the application for the Pharo IDE, not for anything… if you are developing your own application, you want and need to create an application that is the starting point of your program.
This will allow you later to better control a lot of things, like theme, workflow, icons… and to handle your application resources in general withing the exclusive context of your own application.
You can create any component within the context of the application:
presenter := MyPresenter newApplication: myApplication.
but this is recommended just for “top level” presenters (e.g. the first window of your application, or generally top level windows).
The generaly good way to create other presenters (even dialogs) is within the context of the POM in which you are inserted using the new* scripting interface or the instantiate:, instantiate:on: methods, e.g. :
myPresenter := self instantiate: MyDialog on: aModelForThisDialog.
"you can use also: myPresenter := self instantiate: MyDialog"
myPresenter openModal.
This will have some immediate good effects:
your dialog will inherit the same application resources than your parent component.
in some back-ends, the fact that the dialog has a parent window is used to execute the modal part in a more restrained way.
Yes, that means your UI interaction needs to be closer to other UI parts and not anywhere (and everywhere) in the system… that’s called a good architecture 😜.
There are a lot of patterns you can apply if you need to interact with the user deeper in your program you can choose how to do it depending on your case: splitting your case in “interactionable cases”, passing a variable, throwing a resumable notification (ok, maybe this one is not really a good one)… you choose, but the rule of thumb here is: you shall not instantiate presenters outside of its POM.