HELP HANDLING ERRORS IN MVP

Design Pattern: MVP -> MODEL-VIEW-PRESENTER Interaction with user - presenter calls logic on model - model updates presenter - presenter updates view and/or calls new logic on model now assume there is code in model that throws errors (parameter validation for example): in presenter: try { model.doSomething(); } catch (error) { view.showError(blabla); } is it better this way, or is it better like this: in presenter: model.doSomething(); in model: if (name.length < 2) { notifyObservers(ModelEvent.NOT_ENOUGH_NAME_LENGTH); return; } then in presenter: update(ModelEvent event) { switch (event) { case NOT_ENOUGH_NAME_LENGTH: view.showError(blabla); break; } }
17 Replies
JavaBot
JavaBot•7mo ago
⌛ This post has been reserved for your question.
Hey @userexit! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
JavaBot
JavaBot•7mo ago
Please format your code to make it more readable. For java, it should look like this:
​`​`​`​java
public void foo() {

}
​`​`​`​
​`​`​`​java
public void foo() {

}
​`​`​`​
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
userexit
userexitOP•7mo ago
yeah but the notification of the error should it be try {} catch or should it be observable, observer or do i not understand what u mean with interfaces the interface its implemented by presenter or by my view i have an interface like that
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
userexit
userexitOP•7mo ago
well i have a class because i have multiple displays i mean its mostly
userexit
userexitOP•7mo ago
No description
userexit
userexitOP•7mo ago
mostly this if no st ation is selected then we cant save nor search searching involves launching djik algorithm to find shortest path
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
userexit
userexitOP•7mo ago
the button is part of the view presenter has access to all views and model but presenters only job is to update view and model based on their interactions so model has to inform presenter that it doesnt have enough values or some are incorrect and then its the presenters job to update view and model presenter is devoid of any logic
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
userexit
userexitOP•7mo ago
no it wont what ur saying is interesting @borgrel what is the first step of setting up my program like that
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
userexit
userexitOP•7mo ago
wdym by any means a program wants >? as in the model or the presenter
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
userexit
userexitOP•7mo ago
this sounds quite complex for a beginner like me do u have any good ressources to learn more bt this @borgrel
JavaBot
JavaBot•7mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server