Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8731493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:15:13+00:00 2026-06-13T09:15:13+00:00

I was wondering whether the use of a decorator pattern is good in case

  • 0

I was wondering whether the use of a decorator pattern is good in case I want my model (“M part” of MVC) to raise Exceptions depending on their origin. I explain myself.

I have a class called Game which is a part of the Model. I have two Views : a GUI and a command line. I want my model to raise an Exception for command line view when the user enters a character instead of a number (for example). Of course I don’t want this Exception to be handled by the model as it “belongs” to the command line and not to the Model itself.

To encapsulate those two different behaviors, I plan to decorate the Game class with two classes : CommandLineGame and GUIGame which have only one attribute : Game and handle their own kind of Exception. Is it a good idea ? Is there a better one ? The problem of such a solution is that every model class raising Exception depending on its origin has to be decorated…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:15:14+00:00Added an answer on June 13, 2026 at 9:15 am

    What you are describing in the example is “input validation”. Strictly speaking*, this belongs in the Controller (“C Part”) of MVC.

    The separation of concerns for MVC decomposes as follows:

    • View is there to 1) present a UI for the user to evaluate the state of the program (Also, what your program looks like visually) and 2) to receive the user’s expression of intent (receive raw instructions on what they may want to do)
    • Controller is the actual interpreter of these “actions” or “intentions” from the user. It decides what it means for a user to click a particular button and what to call in your model. It decides whether a particular input actually makes sense given context from the UI (and in some case from the model).
    • Model should be View/Controller agnostic (Meaning the model should have no knowledge of the View/Controller). It should only be about the internal representation of what you are trying to “model”. The advantage of doing it this way: you can have many different UIs, or change your existing UIs without affecting the model.

    Overall, the idea is to lower coupling and increase cohesion.

    I hope that makes sense =)

    Depending on the language / framework, the lines between MVC components get blurred a bit. Some idioms will lump most of Controller into the View, but the encapsulation of logic should stay relatively similar.

    *In practice, for defensive programming, input validation is done twice for mutual suspicion: they are broken down into client-side mediation and server-side mediation:

    • In this case, the Model part should handle the “server-side” mediation: it should check that the arguments passed to its functions actually make sense before proceeding.
    • Similarly, the Controller/View part should check the input as part of “client-side” mediation, so that it can warn the user right away, without passing it back to the model, and then eventually back to the view.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Model-View-Presentation Model in my application and I am wondering whether I need
I want to use MongoEngine for my next project. Now I'm wondering whether I
I am wondering whether anyone came up with good use cases of the $^
I am working on an MVC project and was wondering whether to use Basic
I wondering whether use a webView to create a complex text area done with
I am wondering whether I can use the this keyword inside a C# lambda,
I was wondering whether you could use a trick of the compiler to include
I'm learning the Google Maps API and I was wondering whether I can use
I'm currently programming a client application and I'm wondering whether I should use the
I'm wondering whether anyone has been able to use the Microsoft Chart control in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.