I have a dialog, Authentication dialog, that is going to be required in different parts of my application. What would be the best design practice to be able to effeciently call the dialog and the logic behind it (seperate classes) in different points of the program?
EG:
User starts program – login required
User wants to view encrypted data – confirmation of password required
User wants to change password – confirmation of current password required.
So what would be a good way to implement this?
Any suggestions are welcome?
Perhaps not the simplest solution to implement, but you could look into using Aspect Oriented Programming. You could then annotate each method which requires user login. This makes the code clean and readable.
The AOP framework would weave in the required code to handle the user confirmation in your method.
Or do the same thing inside the methods manually:
You could have ConfirmUser return a bool instead of an exception. That’s another discussion, and depends on your application. If you deny operations in lower code layers, an exception is the way to go. A try/catch makes you put the error handling at the bottom of the function, while a returning bool requires and if statement at the top.
vs
You could implement both ConfirmUser and ConfirmPassword, or have both in the same method with a parameter, perhaps an enum to say what you need to verify.