In Java's documentation, it states:
Don't allow subclasses to override methods. The simplest way to do this is to declare the class as final. A more sophisticated approach is to make the constructor private and construct instances in factory methods.
From Clean Code(Page 25):
When constructors are overloaded, use static factory methods with names that describe the arguments
For example:
Complex fulcrumpoint = Complex.FromRealNumber(23.0);
is generally better than
Complex fulcrumPoint = new Complex(23.0);
But according to the comments to this answer, when it comes to this code:
private Weapon(String name, int damage)
{
this.name = name;
this.damage = damage;
}
public void attack(Enemy enemy){ // code to cause damage to enemy }
public static Weapon Sword(String name, damage){
return new Weapon(name, damage);
}
public static Weapon Sniper(String name, damage){
return new Weapon(name, damage);
}
It'll compile and execute, but it violates the Principle of least astonishment.
Did the author of Clean Code violate the Principle of Least Astonishment to write what is considered clean code?