Talking about JAVA

Objects and classes

Object
-oriented programming Object -oriented programming (OOP for short) is made up of objects. Each object exposes a specific function to the user and hides the implementation. As long as the object meets the requirements, there is no need to focus on the specific implementation process.
Traditional structured programming solves problems by designing a series of processes. Once these processes are determined, it is necessary to start thinking about the way to store data. OOP is an algorithm that considers data first and then considers operating data.

Classes
Classes are templates and blueprints for constructing objects. For example: the bread we usually eat is an object, and the machine that makes bread is a class. A class construction object is an instance of creating a class.

Encapsulation ·
An important concept related to objects. Combining data and behavior in one package hides data and implementation methods from users. The data is called the instance domain, and the process of manipulating the data is called the method. For a specific object, it has its own current state, that is, a specific instance domain. As long as the method sends a message to the object, it is possible to change the state. Encapsulation gives the object the characteristics of a black box. The data of the object can only be accessed by the method of the object. You cannot allow methods in a class to access methods in other classes. This means that a class can comprehensively change the way data is stored, as long as the data is manipulated in the same way, other objects will not know the changes.
Object
Three characteristics of object:

  1. Behavior-what methods can be used
  2. State—the reaction of the application method object
  3. Identification—Identify different objects with the same behavior and status.
    Instances of all objects of the same class are similar. The method called by the object determines the behavior of the object.
    The state of the object is the information describing the state of the object. The state of the object must be called to change.
    The state of an object cannot completely describe an object. Each object has a unique identity.
    The state of the object affects the behavior.
    Recognition class In
    procedural programming, you must start with the main function at the top. Object-oriented has no top. So the prime minister starts with the design class and adds methods to the class. The simple method rule for identifying classes is to find nouns in the process of analyzing the problem, and the method corresponds to the verb.
    Relationship between classes
    Dependency, aggregation, inheritance
    If a method of a class needs to operate an object of another class, then there is a dependency relationship between the two classes
    . An object of
    one class contains an object of another class. The method, as well as the extension method, is inheritance
Published 74 original articles · won 15 · views 4095

Guess you like

Origin blog.csdn.net/V2636011127/article/details/104144859