...
The following software design principles are well agreed to at Pentaho. Understand these and keep them in-mind as you develop software with Pentaho
General Coding Guidance
Validate all inputs
Don't trust that you'll be given what you need or expect. Other's may use your code incorrectly or the system may become corrupt or be misconfigured. Validate inputs as soon as you receive them and raise appropriate exceptions as needed. If an input is optional, check it's presence at the start and set it to the default as soon as you can. NOTE: we will likely move a lot of component validation over to a framework like BVal in the future to reduce boilerplate in the implementation classes.
What to throw?
NullPointerException
If someone passes you a null value, an NPE is likely to eventually result. Throw one right at the start instead of letting execution continue potentially putting the system in an inconsistent state.
IllegalArgumentException
This can be thrown for null as well, more of a personal style choice. It's more appropriate when the input is the correct type (not null) but an invalid value (Integer out of bounds, etc.)
IllegalStateException
More related to when a method is called than what is passed. If someone is invoking a method and the state of the class is not prepared, an IllegalStateException is a good choice.
Design Principles
- DRY (Don't Repeat Yourself)
http://en.wikipedia.org/wiki/Don%27t_repeat_yourself - Separation of Concerns
http://en.wikipedia.org/wiki/Separation_of_concerns - Encapsulation
http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) - Dependency Abstraction through Interfaces
Dependencies between classes should be through interfaces not classes. - SOLID
http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)- Single Responsibility
http://en.wikipedia.org/wiki/Single_responsibility_principle - Open/Closed
http://en.wikipedia.org/wiki/Open/closed_principle - Liskov Substitution
http://en.wikipedia.org/wiki/Liskov_substitution_principle - Interface Segregation
http://en.wikipedia.org/wiki/Interface_segregation_principle - Dependency Inversion - a superset of (Service Locator, Factory, Dependency Injection)
http://en.wikipedia.org/wiki/Dependency_inversion_principle
- Single Responsibility