c# - A very basic question about the way GUI integrated with the Logic classes -


Assuming I have a large input form, which represent classes, I can load this input into class instances Need to do this i clearly include this input (some very complex verification) check, obviously the logic level already contains these input validation The question is what am I doing with Gui.

Would I just rewrite those beliefs in a very ugly manner in the GUI

or in some static methods in the logic level, those methods are used in GUI and the logic level , But still it is making a duplicate of validating itself (firstly Guai admits himself, then logic confirms what it has been sent to)

Or just believe me Should i Cover the code that use the logic layer, with an attempt block, and then, if the exception is thrown, inform the user that something is not right (without giving it a chance to know

Or should I expose the exception, the way I expose them to the names of parameters, squares and names that they probably will not understand.

Or for every error I want A special exception class , And in this way the user actually has the problem, but maybe make hundred of possible exceptions

or should I separate it from the Nipple exception, in which everyone is involved, the exact error Describes the content, then grab those exceptions, and check the enum and inform the problem to the user, but grab the app by catching inevitable exceptions at all times.

Or did anyone (someone has given me this proposal, this is not my idea, do not shout at me: D) to validate the input in the logic level, and only check it in Guinea (like this It seems to me a terrible solution: D)

More important questions - Where should I learn such things? Usually my tendency is very good, but I do not want to invent the wheel unnecessarily .. (I am sure that for the basic things already in the conventions that you have bombarded every day).

Thanks a lot!

Definitely you should validate user input if the input and validation logic are as complex, as you It is said, it is even more important to validate the input in the GUI, in this way it makes the user clear what the expected values ​​are, and if there are any errors, what are they? Bonus points if you can suggest fixing these errors!

This does not really help the user to see the exception and exception details - so try to avoid that.

Also, because you are working with input recognition in the GUI, and poor input is an expectation, and is not really out of normal, using the exception is not a good idea to have a simple IsValid () to check whether something is valid or not is better. I always adhere to the rule which is "for exceptions to exceptional circumstances."

So if you accept that recognition in the GUI is a good thing, then the next question is how?

You say that you already have a lot of validity, but it does not seem that your validation logic is available separately. A practice which I have always found useful, is to keep the verification code separate from the other business logic. It allows you to re-use the validity logic, where appropriate, and in this case, you can use your business objects and the GUIs Between the same verification logic will allow sharing. Obviously, there are many design approaches and frameworks to do this, but the fundamental principle is a "separation of concerns" - keep validation logic separate and make it available for use. When you say that "Some statics are written in the logic layer, then use those methods and think" in the logic layer the same way, and it is an approach that has been proven to work.

Just for clarity - I'm not suggesting that you also put validation logic in the GUI. Instead, provide the validation logic used by the GUI. The only part of validation in GUI is the part that displays verification (to the user) to verify (submitting) the user and recognizing that part.

EDIT:

I do not want to sound like Shil for any particular design philosophy, but recently I am working more on using domain driven design principles. I've found that it works very well, and it addresses many questions you ask, there are some questions on this so that you can give more information about what it is and where are some resources:

< Besides, read one here:

Edit 2:

Also read a useful (and related):


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -