Object-Oriented Programming (Basic) 11: Phased Knowledge Supplement

11.1 Attribute assignment process in a class

1. In the attributes of the class, what positions can be assigned to the attributes?

① Default initialization

② Explicit initialization

③ Initialization in the constructor

④ Assign values ​​to attributes by means of "object.property" or "object.method"

2. What is the order in which these positions are executed?

Sequence: ① - ② - ③ - ④

3. Description:

  • ①, ②, and ③ in the above are only executed once during the object creation process.
  • ④ is executed after the object is created, and can be executed multiple times according to requirements.

11.2 JavaBean

  • JavaBean is a reusable component written in Java language.

    • It's like you made a wrench, which will be used in many places. This wrench also serves multiple functions (you can use this wrench to wrench, hammer, pry, etc.), and this wrench is a component.
  • The so-called JavaBean refers to a Java class that meets the following standards:

    • class is public
    • has a public constructor with no arguments
    • There are attributes, and there are corresponding get and set methods
  • Users can use JavaBean to package functions, processing, values, database access and any other objects that can be created with Java code, and other developers can use these through internal JSP pages, Servlets, other JavaBean, applet programs or applications object. Users can think that JavaBean provides a function of copying and pasting anytime and anywhere without caring about any changes.

  • As mentioned in "Think in Java", JavaBean was originally implemented for the visual programming of Java GUI. You drag the IDE construction tool to create a GUI component (such as a multi-select box), but the tool actually creates a Java class for you, and exposes the properties of the class for you to modify and adjust, and exposes the event listener.

  • example

    public class JavaBean {
        private String name; // 属性一般定义为private
        private int age;
        public JavaBean() {
        }
        public int getAge() {
            return age;
        }
        public void setAge(int a) {
            age = a;
        }
        public String getName() {
            return name;
        }
        public void setName(String n) {
            name = n;
        }
    }
    
    

11.3 UML Class Diagrams

  • UML (Unified Modeling Language, Unified Modeling Language), a graphical language used to describe 软件模型and .架构

  • Commonly used UML tool software is PowerDesinger, Roseand Enterprise Architect.

  • UML tool software can not only draw various diagrams required in software development, but also generate corresponding source codes.

  • In software development, use UML类图can more intuitively describe the internal structure of a class (class attributes and operations) and the relationship between classes (such as association, dependency, aggregation, etc.).

    • + means public type, - means private type, # means protected type
    • Method writing:
      method type (+, -) method name (parameter name: parameter type): return value type
    • Italics indicate abstract methods or classes.

 

Guess you like

Origin blog.csdn.net/swx595182208/article/details/129975526