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
⌛
This post has been reserved for your question.
Hey @userexit! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose 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.
Please format your code to make it more readable. For java, it should look like this:
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
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•7mo ago
Message Not Public
Sign In & Join Server To View
well i have a class because i have multiple displays
i mean its mostly
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•7mo ago
Message Not Public
Sign In & Join Server To View
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•7mo ago
Message Not Public
Sign In & Join Server To View
no it wont
what ur saying is interesting @borgrel
what is the first step of setting up my program like that
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
wdym by any means a program wants >?
as in the model
or the presenter
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
this sounds quite complex for a beginner like me
do u have any good ressources to learn more bt this @borgrel
💤
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.