Java. The designer that uses the grid when it's necessary?



  • I met such a design in a learning example.

    public class Vehicle {
      private String color;
    

    //Constructor
    Vehicle(String c) {
    this.setColor(c);
    }

    // Setter
    public void setColor(String c) {
    this.color = c;
    }
    }

    As I understand, the grid is used to give meaning to the private variable that the designer is capable of. Why use a designer that uses a grid that uses the variable if you can use the designer? There are cases where it is necessary, or this is just a theory example, what is it?



  • Bad training. I wouldn't recommend the use of grids inside the designer, especially if the grid was simple. If the grid contains a lot of things, then it would be better to re-examine the class structure, perhaps it would be better to use Bilder patter to create a class copy. The main problem with the grids inside the designer (and, more specifically, with the grids that can be redefined) is what they can create a lot of problems if the method is redesigned.

    JAVA: Effective programming. 2nd edition, Joshua Bloch. Article 17.

    Class designers shall not cause reordered methodsdirectly or indirectly. Violation of this rule may lead to the accidental completion of the programme. Super class designer The pre-class designer shall be performed, and the reordering method in the sub-class will be called before the designer of this sub-class is started. And if the reassigned method depends on The initialization of the grading designer, this The method will not work as expected.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2