Best Practices

What to Avoid in Your Design

This note will list few things you should try to avoid in your design. Please also see notes on SOLID Principles and summary of additional design principles and best practices.

  1. Run-Time Type Identification (RTTI)

    • Design that require you to check for the actual type of the reference object should be avoided (e.g. if(type(something) = something, do something). 

  2. Cyclomatic complexity (CC)

EJB Programming Model and POJO Programming Model

Enterprise Java Bean (EJB)

Enterprise Java Bean (EJB) was the Java EE way for creatng enterprise applications without worrying about middleware requirements such as transaction management, persistence, security, distribution, remoting etc. 

The older EJB programming model however had many problems and POJO programming model emerged as an alternative means to solve those problems. 


Techniques and Considerations for Cleaner Error Handling in your Program

Exceptions should be preferred over error codes as returning error codes will force you to have an “if” statement to check for error code, which may be confusing to some readers and there is also a chance that the caller may forget to check for error codes. If you use error codes, you will also need to have some class that defines all error codes and all classes that use those error codes will be dependent on this class.

Formatting the Lines of Code in your Program for Better Readability and Maintainability

Is formatting your code important? Formatting your code properly is as important as working code. Proper formatting increases readability and hence maintainability, and also give readers the impression that the code was written by professionals.  Let us quickly see some of the formatting issues from vertical as well as horizontal perspectives.


Writing Good Comments and Avoiding Bad Comments in your Program

Are comments needed in your programs? If your code is very clear and expressive, then you won’t ideally need comments. By naming your identifiers correctly you can avoid the need for comments in lot of places within your code. So why learn about writing good comments? Due to reasons including the limitations in expressiveness of a programming language, we may have to still use comments, and for these use cases we will need to learn to write good comments.


Writing Cleaner Methods in your Program

Below simple list of principles and practices can help you write cleaner methods in your program:

  1. Methods should be as small as possible and should have descriptive names that explain its purpose without the need of any extra comments. Bigger methods should be refactored to move contents that can be grouped together, into other methods with descriptive names that reflect the task done by that method and then invoke those methods from the original method.

Naming the Identifiers Correctly in your Program

Is naming identifiers like classes, methods and variables important in developing clean code? It is.

Below is a set of simple rules that you can use as a quick reference to name your identifiers correctly:

  1. Use intention revealing names that can explicitly tell why it exists, what it does and how it is used, so that others can easily understand the code. E.g. int elapsedTimeInDays instead of int d.

Additional Object Oriented Design Principles and Best Practices

Object Oriented Design principles are very important and are sometimes considered even more important than design patterns. All design patterns are based on one or more of the design principles. Having thorough understanding of the design principles will help you understand the design paterns better and faster, and will even help you solve many design scenarios if you can't find a design pattern fitting that scenario.

Best Practices for Multithreading in Java

This article lays down some of the best practices which you can use during your design or code reviews, and assumes that you are familiar with the basics of mutithreading in java available at articles/multithreading.

Best Practices for Using and Writing Exceptions in Java

This article lays down some of the best practices which you can use during your design or code reviews, and assumes that you are familiar with the basics of exceptions in Java. Exceptions should be only used for exceptional conditions. It should not be used for control flow using techniques that might look very clever, like catching an exception and ending a loop.   


Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within!!!