Enterprise Best Practices to be used while working on labs. The first set of best practices are as follows.
1. Working in n-tier architecture
- Separated the core logic from the presentation layer
- Keep the entry point of Presentation Layer LEAN
- Modularize the logic into separate files, classes or a BL project
2. Boiler Plating code
- While creating a project, always create the skeleton
then fill in the logic in the right places
- Example:
# Create the projects in the respective layers
# Inside each project, create the classes with inheritance or association relations, with empty
properties and methods without logic
# Compile your project. Compilation should succeed
# Now, for the given set of requirements for a module, only add the logic in the relevant classes
and methods
3. Exception Handling
- The lower level tiers like DAL, BL should throw exceptions
when such a case is encountered
throw new Exception("exception message");
- The higher level tiers like PL, must include the try--catch
block to catch any kind of exceptions which were thrown from
the lower tiers
try{
//suspecting code that could create issues
}
catch(Exception ex){
//Print exception
}
- For exception handling, usually a custom strategy can be adopted, where third-party tools can be
used to log the exceptions for further analysis, such as using log files or database. At the coding
level, all exceptions should be thrown from the lower layers upwards towards the Presentation
Layer. At intermediate levels, specific exceptions can be added to error log files or database, while
at the Presentation Layer, a friendly message indicating something has gone wrong could be given
with a link to contact support.
No comments:
Post a Comment