Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

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

  1. DRY (Don't Repeat Yourself)
    http://en.wikipedia.org/wiki/Don%27t_repeat_yourself
  2. Separation of Concerns
    http://en.wikipedia.org/wiki/Separation_of_concerns
  3. Encapsulation
    http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming)
  4. Dependency Abstraction through Interfaces
    Dependencies between classes should be through interfaces not classes.
  5. SOLID
    http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
    1. Single Responsibility
      http://en.wikipedia.org/wiki/Single_responsibility_principle
    2. Open/Closed
      http://en.wikipedia.org/wiki/Open/closed_principle
    3. Liskov Substitution
      http://en.wikipedia.org/wiki/Liskov_substitution_principle
    4. Interface Segregation
      http://en.wikipedia.org/wiki/Interface_segregation_principle
    5. Dependency Inversion - a superset of (Service Locator, Factory, Dependency Injection)
      http://en.wikipedia.org/wiki/Dependency_inversion_principle