Effective Java Chapter 4 15-22

Chapter 4. Classes and Interfaces

15. Minimize accessibility for classes and member variables

16. In public classes, use accessor methods and don't make fields public

17. Minimize variability

18. Choose composition over inheritance

19. Design and documentation for inheritance should be done. If not, inheritance should be prohibited

20. Prioritize interfaces over abstract classes

https://ja.wikipedia.org/wiki/Mixin

http://equj65.net/tech/java8mixin/

21. Design the interface for the future

22. Use the interface only for type definition


// Constant utility class

public interface PhysicalConstants {

    static final double AVOGADROS_NUMBER = 6.02214199e23;

    static final double BOLTZMANN_CONSTANT = 1.3806503e-23;

    static final double ELECTRON_MASS = 9.10938188e-31;

}


// Use of static import to avoid qualifying constants

import static com.effectivejava.science.PhysicalConstants.*;

 public class Test {

    double  atoms(double mols) {

        return AVOGADROS_NUMBER * mols;

    }

    ...

    // Many more uses of PhysicalConstants justify static import

Recommended Posts

Effective Java Chapter 6 34-35
Effective Java Chapter 4 15-22
Effective Java Chapter 3
Effective Java 3rd Edition Chapter 5 Generics
Effective Java 3rd Edition Chapter 8 Methods
[Read Effective Java] Chapter 2 Item 7 "Avoid Finalizers"
Effective Java 3rd Edition Chapter 9 Program General
Java Performance Chapter 1 Introduction
effective java 3rd summary
Builder pattern (Effective Java)
Java Performance Chapter 3 Java Performance Toolbox
Effective Java 3rd Edition Chapter 6 enums and annotations
Effective Java 3rd Edition Chapter 4 Classes and Interfaces
[Read Effective Java] Chapter 3 Item 10 "Always Override toString"
Effective Java 3rd Edition Chapter 7 Lambda and Streams
I started Java Gold (Chapter 1-1)
[Read Effective Java] Chapter 3 Item 12 "Considering Implementation of Comparable"
[Read Effective Java] Chapter 2 Item 6 "Remove obsolete object references"
Java Performance Chapter 2 Performance Testing Approach
Java
Effective Java 3rd Edition Chapter 2 Object Creation and Disappearance
Java
From Ineffective Java to Effective Java
Effective Java 3rd Edition Chapter 3 Methods Common to All Objects
[Effective Java] Remove obsolete object references
Java Performance Chapter 5 Garbage Collection Basics
[Effective Java] Avoid creating unnecessary objects
[Read Effective Java] Chapter 2 Item 4 "Force uninstantiation with a private constructor"
[Read Effective Java] Chapter 3 Item 9 "When overriding equals, always override hashCode"
[Read Effective Java] Chapter 2 Item 5 "Avoid the creation of unnecessary objects"
Java learning (0)
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
[Java] Module
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
java (override)
java (method)
Java Day 2018
Java string
java (array)
Java static
Java serialization
java beginner 4
[Read Effective Java] Chapter 2 Item 1 "Consider static factory methods instead of constructors"
JAVA paid
Studying Java ―― 4
Java (set)
java shellsort
[Java] compareTo
Studying Java -5
java reflexes
java (interface)