Java Best PracticesPosted: August 28, 2011
When creating a Java application, the following best practices should be considered:
- Program to an interface, not an implementation.
- A class should have only one reason to change.
- Identify the code that vary and separate it from the code that remains the same.
- No principle is a law. Principles just provide guidance. Hence should be used when and where they are helpful.
- All designs have tradeoffs like abstraction vs speed, time vs space. Hence, all factors should be taken into account before applying them.
- Favor composition over inheritance.
- Classes should be open for extension but closed for modification.
- Depend on abstraction. Do not depend on concretion.
- Only talk to your friend.