Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am designing a small application that is really justa gui for a command line using vb.net.

Question 1.

Should messages(msgbox) to the user come from the UI or should messages come from subs and functions that the UI calls.

Question 2.

Should subs and functions throw new exceptions to the UI or should they be containd in the sub/function

Question 3.

Should if statements be used at the UI level or should users input be passed to subs and functions for if statement processing ?

share|improve this question
add comment

1 Answer

Your questions are pretty broad and cannot really be answered without making a lot of assumptions or giving many alternatives and considerations. From the questions it seems you are looking for rules about what logic goes where. That is generally known as layering. The most common pattern being having three layers: UI; Business (Application) and Data(base). This answer on SO and the links contained within it, will probably help you on your way.

With regard t0 1: The message box should not be displayed by the subs/functions. Message boxes are UI specific implementations and a concern for the UI. The message displayed by the message box can of course come from the subs/functions. If the sub does not return an error message directly but an error code, it is fine to have a separate sub (in the application layer) to return messages based on an error code. This could be part of a separate "localizaion" service when dealing with a multi-lingual UI.

With regard to 2: Depends. They can throw exceptions or they can contain them and return an error code. If you are even remotely considering putting the subs/funcions in a separate module (exe or dll): exceptions should never cross module boundaries. In that case containing exceptions and returning error codes is the way to go.

With regard to 3: The UI can have logic, but that logic should be confined to UI stuff, like enabling and disabling controls. Validation is a business/domain/application concern and the UI should defer to that layer. It should of course have logic, including if statements :-) to process the results of that validation and reflect it in the UI.

share|improve this answer
    
You should never have any validation in the UI? –  JeffO Jun 14 '13 at 12:20
    
@JeffO: You can have validation in the UI, but that should only be in addition to (and probably is a subset of) the validation in the business/domain layer. Especially when you have a (multi-tier) client/server architecture. Any validation done in a client (to enhance the UI experience or avoid continual round-tripping to the server) cannot be relied on by the server. –  Marjan Venema Jun 14 '13 at 15:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.