Dabai became the sixteenth day of the Java software siege lion (the difference between object-oriented and process-oriented, class and object concepts, class definition)

1. The difference between object-oriented and process-oriented

  • Process-oriented: The main focus is: the specific process of implementation, causality [Development ideas of integrated graphics]
    Advantages: For programs with relatively simple business logic, rapid development can be achieved, and the initial investment cost is low.
    Disadvantages: It is difficult to solve very complex business logic in a process-oriented approach. In addition, the process-oriented approach leads to a very high degree of "coupling" between software elements. As long as there is a problem in one of the links, the entire system will be affected, resulting in the final Software expansion is poor. In addition, since there is no concept of independent bodies, component reuse cannot be achieved.
  • Object-oriented: The main focus is: what functions the object [independent body] can accomplish. [Development ideas for discrete graphics cards]
    Advantages: low coupling and strong expansion capabilities. It is easier to solve more complex business logic in the real world, and the components are reusable.
    Disadvantages: The initial investment cost is high, the extraction of independent entities is required, and a lot of system analysis and design are required.
  • C language is purely process-oriented, C++ semi-object-oriented, Java purely object-oriented

2. Three characteristics of object-oriented

  • Package
  • inherit
  • Polymorphism

Note: All object-oriented programming languages ​​have these three characteristics.

Use an object-oriented approach to develop a software. During the life cycle: [OO object-oriented approach is used throughout the entire life cycle]

  • Object-oriented analysis: OOA
  • Object-oriented design: OOD
  • Object-oriented programming: OOP

3. The concept of class objects

What is a class?

  • Class does not exist in the real world, it is a template and a concept. It is the result of the human brain thinking abstractly.
  • A class represents a kind of thing.
  • In the real world, object A and object B have common characteristics, abstract and summarize a template, this template is called a class.

What is an object?

  • Objects are actual individuals. Actually exist in the real world.

Software development process:

  • The programmer first observes the real world and finds objects in the real world
  • After searching for N objects, it is found that all objects have common characteristics
  • The programmer forms a template in the brain [class]
  • Java programmers can express this class through java code
  • There is a class definition in the Java program
  • Then you can create objects through the class
  • After you have objects, you can let them directly collaborate to form a system.

Class-[Instantiate] -> Object

Object is also called instance/instance

Object-[Abstract] -> Class

Focus:

  • Class describes the common characteristics of objects.
  • Common features such as: height feature.
    When accessing this height feature, you must first create an object, and access this feature through the object. Because this feature is specific to an object, the value is different. Some subjects have a height of 1.80 and some have a height of 2.80.

What information does a class mainly describe?

A class mainly describes: state + action .
Status information: name, height, gender, age.
Action information: eating, drinking, playing, and having fun

  • State -> a class attribute
  • Action -> a class method
{
    
    
	属性; //描述对象的状态信息
	方法; //描述对象的动作信息
	}

Note: When the state and action are specific to an object, it is found that the final result may be different.

4. Class definition [Start writing code]

Grammatical structures:

[修饰符列表] class 类名{
    
    
	属性;
	方法;
}

Important: Attributes are usually defined in the form of a variable.

定义一个类,类名Student
Student是一个类。代表了所有的学生对象,是一个学生模板
public class Student{
    
    //定义一个公开的类

//属性【描述的是对象的状态信息】
//属性通常采用变量的方式来定义
//在类体当中,方法体之外定义的变量被称为“成员变量”
//成员变量没有赋值,系统赋默认值:一切向0看齐。
int no;//学号
String name;//姓名
boolean sex;//性别
int age;//年龄
String address;//住址
//方法
//方法描述的是对象的动作信息
//当前例子就只描述属性,不描述方法。

}

All classes in the Java language belong to reference data types.

Take a day off tomorrow and go to Summoner’s Canyon to fight

Guess you like

Origin blog.csdn.net/qq2632246528/article/details/112907486