'Improving the Code One Line at a Time' debugging getsentry
If you are setting essential properties move them to the constructor and remove the methodSample Codepublic class Point { protected int x; protected int y; public Point { this.x=0; this.y=0; } public void setX { this.x=x; } public void setY { this.y=y; } } Point location=new Point; //At this momment, it is not clear which points represent //It is coupled to constructor decision. //Might be null or some other convention location.setX; //Now we have point location.
public class Car { protected int speed; public Car { } public void setSpeed { this.speed=desiredSpeed; } } Car tesla=new Car; //We have no speed?? tesla.setSpeed; //Now our car runs fast//1. We locate setters usage location.setX; location.setY; //2. If you are setting essential properties move //them to the constructor and remove the method public class Point { public Point { this.x=x; this.
public class Car { protected int speed; public Car { this.speed=0 km/h; } public void speed { this.speed=desiredSpeed; } } //1. Locate the setters' usage //3. If you need to change an accidental property // it is not a setter. Remove the setXXX prefix Car tesla=new Car; //Our car is stopped tesla.speed; //We tell the desired speed. We don't set anything //We don't care if the car stores its new speed.